How to run nginx on Docker?

How to run nginx on Docker?

I have Nginx installed on a Docker container, and was trying to run it like this

 

 

Problem with above command  is that the initial process immediately spawns a master Nginx process and some workers, and then quits. Since Docker is only watching the PID of the original command, the container also exit.

How to fix?

Nginx, like all well-behaved programs, can be configured not to self-daemonize. Inorder to start  nginx in foreground, we can use following command
 

 

How to start nginx in Docker container?

You can use the following command to start a containerized nginx application

 

This will start a container with nginx running on foreground, henc container will  not exit.

Leave a Reply

Your email address will not be published. Required fields are marked *