공부합시다!/Container

Docker: alpine + nginx Image 만들기

간서치 2023. 9. 11. 11:34
728x90

alpine 이용하여  간단하게 nginx image를 Dockerifle로 만들어 보겠습니다.

 

1. nginx.conf 파일 작성

user  nginx;
worker_processes  auto;

error_log  /var/log/nginx/error.log notice;
pid        /var/run/nginx.pid;

events {
    worker_connections  1024;
}

http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;
    sendfile on;
    access_log /var/log/nginx/access.log;
    keepalive_timeout 3000;
    server {
        listen 80;
        root /usr/share/nginx/html;
        index   index.html;
        server_name     locahost;
        client_max_body_size 32m;
        error_page 500 502 503 504 /50x.html;
        location = /50x.html {
            root /var/lib/nginx/html;
        }
    }
}

 

2. index.html 파일 작성

 

3. Dockerfile 작성

# step1: base image download
FROM    alpine

# step2: nginx packgae add
RUN     apk add nginx

# step3: nginx.conf add
COPY    nginx.conf      /etc/nginx/nginx.conf
COPY    index.html      /usr/share/nginx/html/index.html
#ADD    https://ko.wordpress.org/wordpress-5.7.8-ko_KR.tar.gz   ./  #ADD Test
# step4: port 80/tcp
EXPOSE  80

# step5: excute
#ENTRYPOINT     ["nginx"]
#CMD            ["-g", "daemon off;"]
CMD     nginx -g 'daemon off;'

 

4. 파일 확인

 

5. docker build 및 build image 확인

 

6. build image 실행 및 확인

728x90