4

I am working in a Dockerfile for PHP-FPM 7.1. I am ending the Dockerfile with the following line:

CMD ["php71-php-fpm"]

Because I am using docker-compose this is how I start up the container:

docker-compose up -d

The container compiles fine (apparently) as per this lines:

Successfully built 014e24455b53
WARNING: Image for service php was built because it did not already exist. To rebuild this image you must use `docker-compose build` or `docker-compose up --build`.
Creating php71-fpm

But it ends with the following error:

ERROR: for php  Cannot start service php: invalid header field value "oci runtime error: container_linux.go:247: starting container process caused \"exec: \\\"php71-php-fpm\\\": executable file not found in $PATH\"\n"
ERROR: Encountered errors while bringing up the project.

I have tried the following:

CMD php71-php-fpm

And the error disappear but then the container exit with code 127:

> docker-compose ps
  Name              Command             State     Ports
-------------------------------------------------------
php71-fpm   /bin/sh -c php71-php-fpm   Exit 127

What I am missing here?

UPDATE

I have found the following answer here:

Value 127 is returned by /bin/sh when the given command is not found within your PATH system variable and it is not a built-in shell command. In other words, the system doesn't understand your command, because it doesn't know where to find the binary you're trying to call.

Which makes me think that the file php71-paths.sh is not being executed so the paths are not setup properly.

Once again, what I am missing?

This php71-fpm will be linked with another container running Nginx (this is a WIP and my way to learn Docker)

Here it's the complete Dockerfile for you to take a look.

Community
  • 1
  • 1
ReynierPM
  • 17,594
  • 53
  • 193
  • 363

1 Answers1

4

I believe you're running into trouble because the default shell run by Docker is not a login shell according to this answer, which means scripts in /etc/profile.d/ don't get processed.

If you need profile processing, try changing your last line to CMD ["/bin/sh", "-l", "-c", "php71-php-fpm"] to invoke a login shell.

Community
  • 1
  • 1
shiv
  • 206
  • 1
  • 7
  • I got the same result as before – ReynierPM Dec 13 '16 at 04:40
  • Are you sure that executable exists on the image? Doing `find / -name php71-php-fpm1` on your image only finds an entry in `/etc/logrotate.d` – shiv Dec 13 '16 at 05:01
  • **Note ** I did originally forget the `-c` in my answer. Sorry about that. But running the image with `CMD ["env"]` vs. `CMD ["/bin/sh", "-l", "-c", "env"]` will show the relevant php dirs in your `PATH` – shiv Dec 13 '16 at 05:05
  • This is the file [php71-paths.sh](https://github.com/reypm/another-lamp-docker/blob/master/php-fpm/container-files/config/init/20-php.sh) that should add the paths, maybe is not being executed at container start, can you take a look to the [Dockerfile](https://github.com/reypm/another-lamp-docker/blob/master/php-fpm/Dockerfile) and let me know is that's the problem and what's the solution in such case? – ReynierPM Dec 13 '16 at 12:10
  • I do believe the container is sourcing the `php71-paths.sh` file if run with `/bin/sh -l -c ...` as evidenced by printing the environment variables in the container using `env`when it's running (`PATH` contains references to `php` directories). However my concern is that the executable named `php71-php-fpm` doesn't actually exist on your image. As stated above, I was unable to find it anywhere in the container's filesystem when it was running. Is that actually the command that needs to be run to start php? Sorry, I can't test your image at the moment. – shiv Dec 13 '16 at 19:44
  • I did found my answer [here](https://developers.redhat.com/blog/2014/12/29/running-php-fpm-in-docker/) thanks to the great Remi (yes from RemiRepo), the solution is: `ENTRYPOINT /opt/remi/php71/root/usr/sbin/php-fpm --nodaemonize`. I have accepted your question because you try to help me all the time. – ReynierPM Dec 14 '16 at 14:14