Docker Community Forums

Share and learn in the Docker community.

Unable to start Nginx from docker file

docker

(Durgesh07) #1

Hi All,
I want to spwan an nginx from docker , via Docker file I am using CMD nginx followed by other configuration in Dockerfile and then run the docker in daemon mode, the container is up but nginx is not started…kindly help what i am missing!!


(Hofwegen266) #2

As stated in my comment, a strong possibility is a syntax error in the nginx config files on the host.

If you copy the default nginx config file to the host, the commands above run fine, but if you introduce a syntax error into the config file on the host, then the container will not run.


prepaid gift balance


(Jjfraney) #3

I’m wondering how to know what you are missing when you have shown very little what you are not missing. What have you discovered about the base docker image, or in the system logs, or in ngnix stderr/stdout? You can exec into the container and look around inside to make sure config is what you want. Some base images use ‘entrypoint’, does yours?


(Durgesh07) #4

docker run -t -d -p 8085:80 --name myname new /usr/sbin/nginx -g "daemon off…Solved my problem!!!


(John Rofrano) #5

It’s also important to understand why that fixed your problem. The Docker container will exit when the main process terminates. Unfortunately, any process that runs as a daemon looks like it has terminated so the container exits. By using "deamon off" you have instructed nginx to run in the foreground so that the container stays alive.

Always run the main process in the foreground when using containers.


(Rochelle184) #6

As stated in my comment, a strong possibility is a syntax error in the nginx config files on the host.

If you copy the default nginx config file to the host, the commands above run fine, but if you introduce a syntax error into the config file on the host, then the container will not run.