도커 컨테이너를 도커 이미지 파일로 저장
저장된 파일을 도커 이미지로 가져오고 도커 컨테이너 생성
연습에서 nginx 도커 이미지를 활용
nginx 도커 이미지로 도커 컨테이너 생성
$ docker run -itd --name my-nginx -h my-nginx -p 18080:80 nginx
컨테이너 응답 확인
$ curl localhost:18080
<!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>
도커 컨테이너의 파일을 도커호스트로 복사
$ docker cp my-nginx:/usr/share/nginx/html/index.html ./index.html
파일 편집
$ vi index.html
<!DOCTYPE html>
<html>
<head>
<title>Welcome to w00j00ng!</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>
편집한 파일을 도커 컨테이너로 복사
$ docker cp ./index.html my-nginx:/usr/share/nginx/html/index.html
도커 컨테이너 재시작 및 응답 확인
$ docker restart my-nginx
$ curl localhost:18080
<!DOCTYPE html>
<html>
<head>
<title>Welcome to w00j00ng!</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>
컨테이너를 도커 이미지 파일로 저장
$ docker export -o ./wj-nginx-img.tar my-nginx
$ ls -alh | grep wj-nginx-img.tar
-rw------- 1 player player 138M Jul 28 18:00 wj-nginx-img.tar
wj-nginx-img.tar
파일을 new-nginx-img
이미지로 저장
$ docker import ./wj-nginx-img.tar wj-nginx-img
$ docker images | grep wj-nginx-img
wj-nginx-img latest 1f95faa733d0 8 seconds ago 140MB
컨테이너 생성
$ docker run -itd --name wj-nginx -h wj-nginx -p 28080:80 wj-nginx-img /bin/bash
프로그램 실행 및 응답 확인
$ docker exec -it wj-nginx service nginx start
2022/07/28 09:08:00 [notice] 18#18: using the "epoll" event method
2022/07/28 09:08:00 [notice] 18#18: nginx/1.23.1
2022/07/28 09:08:00 [notice] 18#18: built by gcc 10.2.1 20210110 (Debian 10.2.1-6)
2022/07/28 09:08:00 [notice] 18#18: OS: Linux 5.10.16.3-microsoft-standard-WSL2
2022/07/28 09:08:00 [notice] 18#18: getrlimit(RLIMIT_NOFILE): 1048576:1048576
2022/07/28 09:08:00 [notice] 19#19: start worker processes
2022/07/28 09:08:00 [notice] 19#19: start worker process 20
2022/07/28 09:08:00 [notice] 19#19: start worker process 21
$ curl localhost:28080
<!DOCTYPE html>
<html>
<head>
<title>Welcome to w00j00ng!</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>