DOCKERFILE: Running multiple CMD. (Starting NGINX and PHP) [duplicate] DOCKERFILE: Running multiple CMD. (Starting NGINX and PHP) [duplicate] nginx nginx

DOCKERFILE: Running multiple CMD. (Starting NGINX and PHP) [duplicate]


start.sh

#!/bin/bash/usr/sbin/service php7.0-fpm start/usr/sbin/service nginx starttail -f /dev/null

Dockerfile

COPY ["start.sh", "/root/start.sh"]WORKDIR /rootCMD ["./start.sh"]

With this, you can put more complex logic in start.sh.


You can replace the CMD line for some like ...

CMD ["/bin/bash", "-c", "/usr/sbin/service php7.0-fpm start && nginx -g 'daemon off;'"]


TL;DR: You don't have an entry point.

Main idea in the Docker is to have one responsibility per container. So, in order to keep running a Docker container you have to start a program in foreground upon container boot.

However, in your Dockerfile, there is no entrypoint to start a program in foreground. So, just after your container boot, your container exits.

So, in order to prevent your container from exiting, just start a program in foreground.

Nginx for instance.

Example scenario:

entrypoint.sh content:

#!/bin/bashservice php7.0-fpm startnginx -g 'daemon off;

somewhere in Dockerfile:

COPY [ "./entrypoint.sh", "/root/entrypoint.sh" ]

at the end of the Dockerfile:

ENTRYPOINT /root/entrypoint.sh