4

I have a Docker container with PHP-FPM installed. To start it with -d option I tried this, but the container exits immediately:

docker run -d --name u12php53 -p 9001:9000 php53 /usr/local/etc/php-fpm.sh 

The content of /usr/local/etc/php-fpm.sh is:

service php5-fpm start && tail -F /var/log/php5-fpm.log 

if I start the docker like this:

docker run -it --name u12php53 -p 9001:9000 -v php53 

and start php-fpm.sh manually, PHP-FPM works fine and its log file is printed to stdout.

The final goal is to configure Docker to start my container with the system starts (or reboots).

2 Answers 2

3

The issue is here: service php5-fpm start. When you execute this command process php-fpm will be detached from shell. But Docker works only while main process is alive.

Try to run php-fpm as in official image: simply remove entrypoint and add CMD ["php-fpm"].

Also, why do you want create your own php-fpm image? may be you can use official image?

Sign up to request clarification or add additional context in comments.

3 Comments

I need PHP 5.3 that is no longer supported, as far as I see. Isn't the main process /usr/local/etc/php-fpm.sh? it does not exit, because I use 'tail -F'. The other question is if I start docker with command 'docker run -d --name u12php53 -p 9001:9000 php53 yes', it does not exit.
thx, i understood what for you build own image. Main process must be started with CMD instruction. Entrypoint usually uses for preparing a container: configuration, make a migration, etc. Could you show me your Dockerfile please?
I described all the PHP-FPM installation procedure here developernote.com/2017/07/… (there is also the Dockerfile). I started with PHP 5.6, but finally installed PHP 5.3 with the similar docker file based on Ubuntu 12.04. Looks like I cannot put this CMD into the Dockerfile, because I did the most of the installations steps manually with bash.
0

Probably the solution is:

docker run -d --name u12php53 -p 9001:9000 -v php53 bash -c '/usr/local/etc/php-fpm.sh' 

probably it is an equivalent of doing this in Dockerfile:

CMD ["sh", "/usr/local/etc/php-fpm.sh"] 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.