3

I have installed PHP 7 (php-fpm and php-cli) and my app is working fine with new PHP, but tests (phpunit) don't because some extensions aren't updated yet.

So I'm thinking to use/create some docker container with PHP 5.6 that would replace my system's (host) php-cli.

For example, if I build container called php56 from Dockerfile that looks like this:

FROM ubuntu:15.10
RUN  apt-get -y update && apt-get install -y php5-cli
ENTRYPOINT ["php"]

and run:

sudo docker run -it php56 -v

I'm getting version info from Docker container, so docker's php-cli 5.6 is working. So I wan't to put docker run command in

/usr/bin/php

so that host use php-cli from docker container. (then php -v would give me PHP 5.6 info not PHP 7.0 version info)

It's not best example, but I hope that you guys will understand what I'm trying to do. If it's not possible to solve it like this, please recommend me other solution.

overdose
  • 41
  • 1
  • 1
  • 5
  • 1
    What do you mean "put `sudo ...` *in* `/usr/bin/php`"? – Etan Reisner Mar 29 '16 at 19:40
  • If I run `php` in terminal, `docker run` command is executing. Basically I'm trying to replace host php-cli with php-cli from docker container. – overdose Mar 29 '16 at 20:19
  • How do you know that *"my app is working fine with new PHP"* if you aren't running your unit-tests on the same version? – thaJeztah Mar 29 '16 at 21:33
  • I don't get any warning/error from php-fpm, all features are working as expected. PHP-fpm 7 and PHP-cli 5.6 would be just temporary solution (on my local dev machine), so I can run tests until extensions are updated. Of course, PHP seven won't be on production until all tests pass. – overdose Mar 30 '16 at 12:54
  • 2
    What's your question about this? Anything not working with the given approach? Also, if "extensions aren't updated yet", what's the exact problem with them? – Nico Haase Jul 03 '21 at 08:15
  • You try to run php execution from docker on host environment?? It contradicts with the idea of containers itself. When you run smth. inside the container it assumes that the execution environment also belongs to this container. Now, what you want is to mount your app(php scripts folder) as a persisten volume to your 5.6 container and obtain test results from it. – Dr. Alexander Mar 04 '22 at 11:24

1 Answers1

0

I did something that looks like what you're looking for: https://github.com/jclaveau/docker-php-multiversion

This adds a php shell script which will run a docker image containing all available PHP versions since 5.6.

You can then run php 5.6 vendor/bin/phpunit or php 7.4 vendor/bin/phpunit, etc.

I embedded it inside a Docker image after a crash of my SSD where I lost all my php.ini configuration so as long as you have Docker.io installed, it would work

Jean Claveau
  • 1,101
  • 1
  • 13
  • 15