yuns
[Docker] 도커 이미지 및 컨테이너 실행2 본문
반응형
nginx
- 웹 서버 소프트웨어로 가벼운과 높은 성능을 목표로 함
- 웹 서버, 리버스 프록시 및 메일 프록시 기능을 가짐
도커에서 nginx 돌려보기
docker pull nginx
docker run -d -p 8000:80 --name nginx-latest nginx:latest
docker pull nginx하면 아래와 같이 작동하면서 nginx 이미지가 docker에 설치된다.
- -p 옵션: docker host 컴퓨터에서 컨테이너에 포트 포워딩을 하고 있음으 ㄹ의미
- docker host 컴퓨터의 8000번 포트가 nginx-latest 컨테이너에 있어서 80번 포트로 연결되어 있다는 것을 의미
- 8000번 포트는 현재 내 컴퓨터에서 들어가는 것으로 이해
- docker host 컴퓨터의 8000번 포트가 nginx-latest 컨테이너에 있어서 80번 포트로 연결되어 있다는 것을 의미
$ docker ps 명령어를 입력할 경우, 아래와 같이 상태를 확인할 수 있음
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f1d2b5c059f9 nginx:latest "/docker-entrypoint.…" 57 seconds ago Up 57 seconds 0.0.0.0:8000->80/tcp nginx-latest
- ports: 0.0.0.0:8000->80/tcp
- docker host에서 8000번 포트에 액세스하면 컨테이너 안에서 실행되고 있는 nginx 서버에 요청 가능
- command에 "nginx - 'daemon off'"라는 명령어가 실행된다고 한다..
- 여기서는 왜 아닌지 모르겠지만 이 명령어의 의미를 간단하게 적어보면
- 이 컨테이너는 foreground에서 nginx가 실행되고 있음을 의미
http://localhost:8000/index.html 에 접속해본다.
- 잘 되었단다.
터미널로 잘 되었는지 확인해보기
curl http://localhost:8000/index.html
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
html { color-scheme: light dark; }
body { width: 35em; margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif; }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>
<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>
<p><em>Thank you for using nginx.</em></p>
</body>
</html>
컨테이너의 표준 출력 확인
nginx 컨테이너 표준 출력 로그 확인
docker logs -f nginx-latest
/docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
/docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
/docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
10-listen-on-ipv6-by-default.sh: info: Getting the checksum of /etc/nginx/conf.d/default.conf
10-listen-on-ipv6-by-default.sh: info: Enabled listen on IPv6 in /etc/nginx/conf.d/default.conf
/docker-entrypoint.sh: Sourcing /docker-entrypoint.d/15-local-resolvers.envsh
/docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
/docker-entrypoint.sh: Launching /docker-entrypoint.d/30-tune-worker-processes.sh
/docker-entrypoint.sh: Configuration complete; ready for start up
2024/04/10 11:35:45 [notice] 1#1: using the "epoll" event method
2024/04/10 11:35:45 [notice] 1#1: nginx/1.25.4
2024/04/10 11:35:45 [notice] 1#1: built by gcc 12.2.0 (Debian 12.2.0-14)
2024/04/10 11:35:45 [notice] 1#1: OS: Linux 5.15.49-linuxkit
2024/04/10 11:35:45 [notice] 1#1: getrlimit(RLIMIT_NOFILE): 1048576:1048576
2024/04/10 11:35:45 [notice] 1#1: start worker processes
2024/04/10 11:35:45 [notice] 1#1: start worker process 29
2024/04/10 11:35:45 [notice] 1#1: start worker process 30
2024/04/10 11:35:45 [notice] 1#1: start worker process 31
2024/04/10 11:35:45 [notice] 1#1: start worker process 32
172.17.0.1 - - [10/Apr/2024:11:44:24 +0000] "GET /index.html HTTP/1.1" 200 615 "-" "curl/8.4.0" "-"
172.17.0.1 - - [10/Apr/2024:11:44:35 +0000] "GET /index.html HTTP/1.1" 200 615 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36" "-"
2024/04/10 11:44:35 [error] 32#32: *2 open() "/usr/share/nginx/html/favicon.ico" failed (2: No such file or directory), client: 172.17.0.1, server: localhost, request: "GET /favicon.ico HTTP/1.1", host: "localhost:8000", referrer: "http://localhost:8000/index.html"
172.17.0.1 - - [10/Apr/2024:11:44:35 +0000] "GET /favicon.ico HTTP/1.1" 404 555 "http://localhost:8000/index.html" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36" "-"
참고
위키백과
IT운용 체제 변화를 위한 데브옵스
반응형
'Docker 공부' 카테고리의 다른 글
[Docker] Docker Compose로 환경 전체 공유 (0) | 2024.04.17 |
---|---|
[Docker] 도커 이미지 및 컨테이너 실행 (3) | 2024.04.08 |
Comments