If nginx is running in a container then your site is going to be 100% dead to the world while Docker isn't running. Users will get a connection error. When nginx is installed directly on your host you can serve a 503 maintenance page that doesn't depend on Docker or any containers running.
Create a new, detached Nginx container with this command: sudo docker run --name docker-nginx -p 80:80 -d nginx.
You can create an NGINX instance in a Docker container using the NGINX Open Source image from Docker Hub. This command creates a container named mynginx1 based on the NGINX image. The command returns the long form of the container ID, which is used in the name of log files; see Managing Logging.
To expand on Charles Duffy's answer, Nginx uses the daemon off
directive to run in the foreground. If it's inconvenient to put this in the configuration file, we can specify it directly on the command line. This makes it easy to run in debug mode (foreground) and directly switch to running in production mode (background) by changing command line args.
To run in foreground:
nginx -g 'daemon off;'
To run in background:
nginx
nginx
, like all well-behaved programs, can be configured not to self-daemonize.
Use the daemon off
configuration directive described in http://wiki.nginx.org/CoreModule.
To expand on John's answer you can also use the Dockerfile
CMD
command as following (in case you want it to self start without additional args)
CMD ["nginx", "-g", "daemon off;"]
Just FYI, as of today (22 October 2019) official Nginx docker images all have line:
CMD ["nginx", "-g", "daemon off;"]
e.g. https://github.com/nginxinc/docker-nginx/blob/23a990403d6dbe102bf2c72ab2f6a239e940e3c3/mainline/alpine/Dockerfile#L117
Adding this command to Dockerfile can disable it:
RUN echo "daemon off;" >> /etc/nginx/nginx.conf
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With