I'm just learning Docker and have a problem with running nginx together with php. This is my Dockerfile
FROM nginx
RUN apt-get update -y
RUN apt-get install php7.4-fpm -y
ADD start.sh /
RUN chmod +x /start.sh
CMD ["/start.sh"]
start.sh content:
#!/bin/bash
service php7.4-fpm start
nginx -g 'daemon off;'
If I omit the last line CMD ["/start.sh"]
, accessing files from the host machine works but php files aren't processed because php7.4-fpm is not running. But when I add this line nginx stops serving any files. Through I can confirm that nginx and php are running inside the container with docker exec nginx-custom service nginx status
and docker exec nginx-custom service php7.4-fpm status
. The nginx error log is empty.
This is the CMD of the original nginx image, which I thought is the only thing that gets overwritten? I guess I have some basic problems in understanding how Docker works at this point.
CMD ["nginx", "-g", "daemon off;"]