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

 

1 2 3   docker run i t p 80:80 nginxfrontend /usr/sbin/nginx  

 

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
 

1 2 3   nginx g ‘daemon off;’  

 

How to start nginx in Docker container?

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

1 2 3   docker run i t p 80:80 nginxfrontend  nginx g ‘daemon off;’  

 

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

Author: , 0000-00-00