Home > Mobile >  Why is CMD daemon off needed for Ubuntu image and not Nginx image docker files?
Why is CMD daemon off needed for Ubuntu image and not Nginx image docker files?

Time:03-12

I had the issue where my docker container would immediately stop after build w/ UBUNTU image and discovered the CMD nginx daemon off, is required for NGINX in some cases. However when I build a docker image with NGINX this is not needed. Can anyone explain or point me to reference material? Docker files as mentioned are below. Both work, but one has to have the daemon off CMD to stay on.

UBUNTU DOCKER FILE:

FROM ubuntu
LABEL maintainer="[email protected]"
RUN apt-get update && apt-get install nginx -y
COPY index.html /var/www/html/
EXPOSE 80
RUN date  "%A, %b %d, %Y %H:%M:%S" >> /var/www/html/index.html
CMD ["nginx","-g","daemon off;"]

NGINX DOCKERFILE:

FROM nginx:latest
LABEL maintainer="[email protected]"
RUN apt-get update && apt-get install nginx -y
COPY ./index.html /usr/share/nginx/html/index.html
WORKDIR /usr/share/nginx/html
EXPOSE 80
RUN date  "%A, %b %d, %Y %H:%M:%S" >> /usr/share/nginx/html/index.html

CodePudding user response:

A Docker image inherits its ENTRYPOINT and/or CMD from its base image. If you look at the nginx image's Dockerfile, it already has the exact CMD line you reference, so you don't need to repeat it in your derived image.

  • Related