nginx 컨테이너 생성
docker run --name nginx nginx
Unable to find image 'nginx:latest' locally
latest: Pulling from library/nginx
177e7ef0df69: Already exists
ea57c53235df: Pull complete
bbdb1fbd4a86: Pull complete
Digest: sha256:b543f6d0983fbc25b9874e22f4fe257a567111da96fd1d8f1b44315f1236398c
Status: Downloaded newer image for nginx:latest
nginx로 접속 테스트를 위해 새 터미널을 열고 다음 명령 실행
curl <http://localhost>
curl: (7) Failed to connect to localhost port 80: Connection refused
컨테이너에 접속 (interactive, tty 옵션 사용)
docker exec -it nginx bash
nginx 접속 테스트 (컨테이너에 curl 설치가 되어 있지 않기 때문에 설치 후 실행)
apt-get update && apt-get install -y curl && curl <http://localhost>
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
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>
컨테이너 쉘 접속 종료
exit
nginx가 구동 중인 터미널로 돌아와서 nginx 종료
Ctrl + c
nginx 컨테이너 제거
컨테이너와 Attach 상태 인 경우 "Ctrl + c"를 입력하여 컨테이너 종료
컨테이너 제거
docker rm nginx
nginx 접속이 가능하도록 컨테이너 생성
docker run --name nginx -p 80:80 nginx
새 터미널에서 접속 확인
curl <http://localhost>
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
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>
컨테이너 제거
컨테이너와 Attach 상태 인 경우 "Ctrl + x"를 입력하여 컨테이너 종료
nginx 컨테이너 제거
docker rm nginx
현재까지는 컨테이너 생성과 동시에 컨테이너에 Attach 되어 터미널 종료 시 컨테이너도 함께 종료되었는데, 실제 서비스에서는 항상 백그라운드에서 동작해야한다.
컨테이너 구동 시 daemon 옵션 사용
docker run -d --name nginx -p 80:80 nginx
71ec54131bfc8310710e5c8c512dea896859b43e6a7114ab2f05d6540be63c16
컨테이너 확인
docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
71ec54131bfc nginx "nginx -g 'daemon of…" 2 minutes ago Up 2 minutes 0.0.0.0:80->80/tcp nginx
접속 확인
curl <http://localhost>
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
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>