Docker Community Forums

Share and learn in the Docker community.

Running multiple commands in compose file

Hi all,

I am trying to run a few commands in my own Nginx container I create from a compose yml file.

Basically, I do the tail -f command simply to keep the container running. And then I also want to start the Nginx and php-fpm service.

My compose file only seems to run the tail -f command, and the start nginx and php-fpm commands dont seem to run. I always have to exec into the container and run those commands manually myself.

Compose yml file:

version: ‘3.7’
image: myown/nginx:latest
- “80:80”
command: tail -f /dev/null && service nginx start && service php7.3-fpm start

Can you please let me know the correct way to do this or alternative way?

Thanks all.


Normally you would put this kind of stuff in a separate file, and use that as entrypoint.

Have you seen that there is allready a php-apache image?

But, the problem you have here is that you put tail -f /dev/null first, the thing with && is that it means “when the command is finished successfully then next command”

and tail -f /dev/null never ends, so try and put it in the end instead, but im not sure that it will 100% work

1 Like

Thanks you were right, tail command needed to be last.

Also I had to wrap it into a bash command as below:
command: bash -c “service nginx start && service php7.3-fpm start && tail -f /dev/null”