Version  안 보이는 Nginx Docker 만들기

ASHAPPYASIKNOW·2022년 6월 29일
1

Docker

목록 보기
7/7
post-thumbnail

최신 버전의 Nginx Docker Container 실행하기

Nginx 최신 버전 다운로드 및 실행

최신-버전의-Nginx-Docker-Container-실행하기

docker search nginx
docker pull nginx:lates
docker run --name mynginx -p 8080:80 -d nginx:latest
docker ps

Nginx Server 접속 및 Version 확인

http://localhost:8080 접속

http://localhost:8080/kevin 접속

Nginx Container 에서 Nginx Config 파일 가져오기

Nginx container에 접속하기

docker exec -it mynginx /bin/bash
whereis nginx

Nginx 환경설정 파일 복사하기

cd /etc/nginx
ls
cat nginx.conf

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;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

    #gzip  on;

    include /etc/nginx/conf.d/*.conf;
}

Custom nginx docker image 만들기

작업 폴더 만들고 이동

cd /mnt/d/Workspace
mkdir docker-examples
cd docker-examples

nginx.conf 파일 만들기

vim nginx.conf

복사한 내용을 기반으로 server_tokens off; 추가

저장하기

Dockerfile 만들기

vim Dockerfile

docker build -t nginx:v1 .

  1. 현재 폴더에 있는 Dockerfile을 기반으로 image를 만든다.
  2. 기본 베이스 이미지는 미리 다운 받아 놓앗던 nginx:latest 이다.
  3. 이미지 생성시 현재 폴더에 있는 nginx.conf 를 image의 /etc/nginx/nginx.conf 에 복사한다.

만들어진 docker image 확인

docker images

만들어진 nginx image로 container 만들어서 실행

docker run --name mynginx -p 8080:80 -d nginx:v1
docker ps

Nginx 접속

사이트 접속 확인

http://localhost:8080

NotFound page 접속 확인

http://localhost:8080/kevin

profile
36.9 It's good time to start something new

1개의 댓글

comment-user-thumbnail
2022년 9월 14일

감사합니다 도움이 많이 되었어요

답글 달기