Nginx on Docker

Docker 2017. 3. 30. 13:14

Run Nginx on Docker 


1. Create Dockerfile

1
2
3
4
FROM nginx
COPY html /usr/share/nginx/html # html directory of content
ADD nginx.conf /etc/nginx/nginx.conf # nignx config file
CMD ["nginx", "-g", "daemon off;"]
cs


2.Create nginx.conf

1
2
3
4
5
6
7
8
9
10
11
12
13
14
user nobody nogroup;
worker_processes auto;          # auto-detect number of logical CPU cores
 
events {
  worker_connections 512;       # set the max number of simultaneous connections (per worker process)
}
 
http {
  server {
    listen *:80;                # Listen for incoming connections from any interface on port 80
    server_name "";             # Don't worry if "Host" HTTP Header is empty or not set
    root /usr/share/nginx/html; # serve static files from here
  }
}
cs


3. Create /html/index.html for test

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
html>
  <head>
    <title>Sample "Hello, World" Application</title>
  </head>
  <body bgcolor=white>
 
    <table border="0" cellpadding="10">
      <tr>
        <td>
          <h1>Sample "Hello, World" Application</h1>
        </td>
      </tr>
    </table>
 
    <p>This is the home page for the HelloWorld Web application. </p>
  </body>
</html>
cs



3. docker build

1
docker build -t docker-nginx .
cs


4. Check docker image

1
2
3
$ docker images
REPOSITORY                                 TAG                 IMAGE ID            CREATED             SIZE
docker-nginx                               latest              c86e2b339c31        About an hour ago   182.5 MB
cs


5. docker run

1
docker run --name docker-nginx -d -p 80:80 docker-nginx
cs


6. Connect [host_ip or localhost]:8080 and Check




 


Posted by 사용자 guru_k

댓글을 달아 주세요