PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, May 15, 2022

[FIXED] Why is CMD daemon off needed for Ubuntu image and not Nginx image docker files?

 May 15, 2022     docker, dockerfile, nginx, ubuntu     No comments   

Issue

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="bnalaska96@yahoo.com"
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="bnalaska96@yahoo.com"
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

Solution

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.



Answered By - David Maze
Answer Checked By - Clifford M. (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing