...
코드개발
Dockerfile 생성
Dockerfile Image 생성
Container Orchestrator를 통한 배포
Container run
Container image Push
실습환경 구축 - VM 구성 테스트
정보 |
---|
이전의 모든 vagrant VM을 지우는 방법
이전의 모든 vagrant box를 지우는 방법
|
먼저 cmd로 들어간다.
코드 블럭 |
---|
$mkdir -p ~/vagrant/ubuntu
$cd ~/vagrant/ubuntu
$vagrant init sysnet4admin/Ubuntu-k8s
$vagrant up |
기동 된 VM 확인(기본 계정 : vagrant/vagrant)
vagrant 명령어로 확인
$ vagrant box list
코드 블럭 $ vagrant ssh default Welcome to Ubuntu 22.04.2 LTS (GNU/Linux 5.19.0-28-generic x86_64) * Documentation: https://help.ubuntu.com * Management: https://landscape.canonical.com * Support: https://ubuntu.com/advantage * Strictly confined Kubernetes makes edge and IoT secure. Learn how MicroK8s just raised the bar for easy, resilient and secure K8s cluster deployment. https://ubuntu.com/engage/secure-kubernetes-at-the-edge Last login: Sat Mar 20 18:04:46 2021 from 10.0.2.2 vagrant@k8s:~$
Docker 기본 명령어에 대해 알아보는 시간을 가지도록 하겠습니다.
1. Image 가져오기
docker image 저장소
...
: 기본 개념에서와 같이 도커는 저장소(registry)에서 이미지를 가져와 사용을 합니다.
vagrant@ubuntu-focal:~$ docker images
vagrant@ubuntu-focal:~$ sudo -
iroot@ubuntu-focal:~#
apt install docker.io
펼치기 | ||
---|---|---|
| ||
|
docker hub 가입
정보 |
---|
docker 이미지 이름 구성 저장소 이름 (Repository Name) : default == docker hub |
$ docker pull nginx:latest
코드 블럭 |
---|
# docker images 명령어를 통해 현재 가지고 있는 이미지 확인
root@ubuntu-focal:~# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE |
이미지를 땡겨 봅시다
root@ubuntu-focal:~# docker images
코드 블럭 |
---|
# tag를 지정해주지 않으면 default로 latest 버전을 가져옵니다.
# tag를 지정할 경우
# docker pull nginx:latest
# 위의 명령어 대로 pull 가능
root@ubuntu-focal:~# docker pull nginx:latest
latest: Pulling from library/nginx
52d2b7f179e3: Pull complete
fd9f026c6310: Pull complete
055fa98b4363: Pull complete
96576293dd29: Pull complete
a7c4092be904: Pull complete
e3b6889c8954: Pull complete
da761d9a302b: Pull complete
Digest: sha256:104c7c5c54f2685f0f46f3be607ce60da7085da3eaa5ad22d3d9f01594295e9c
Status: Downloaded newer image for nginx:latest
docker.io/library/nginx:latest
# 이미지 확인
root@ubuntu-focal:~# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest eea7b3dcba7e 2 weeks ago 187MB
|
이미지를 가져왔으니 이제 실행시켜봐야죠!
...
2. Run Container
docker ps
코드 블럭 |
---|
# docker ps 라는 명령어로 현재 실행중인 컨테이너를 확인합니다.
# docker ps -a -> 중지된 컨테이너까지 모두 출력
root@ubuntu-focal:~# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES |
실행중인 컨테이너가 없네요
root@ubuntu-focal:~# docker run -it -d -p 80:80 --name=nginx nginx:latest
root@ubuntu-focal:~# docker ps
root@ubuntu-focal:~# curl http://localhost:80
코드 블럭 |
---|
# docker run 이라는 명령어로 컨테이너를 실행시켜줍니다.
# docker run <옵션> <이미지 이름> <실행할 파일>
root@ubuntu-focal:~# docker run -it -d -p 80:80 --name=nginx nginx:latest
1303feec17205609e6303e72831084babeaebdfaec3bf9bf0f6f4e4b39082dd1
# 옵션 -i(interactive), -t(Pseudo-tty) -> Bash Shell에 입력 및 출력을 할 수 있습니다.
# 옵션 --name -> 컨테이너의 이름을 지정해 줍니다.
# 옵션 -d -> daemonized
# 옵션 -p -> 포트포워딩
ex) 80:80 = [호스트의 포트] : [컨테이너의 포트]
root@ubuntu-focal:~# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
1303feec1720 nginx:latest "/docker-entrypoint.…" 14 seconds ago Up 14 seconds 0.0.0.0:8080->80/tcp, :::8080->80/tcp nginx
root@ubuntu-focal:~# curl http://localhost:80
<!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 create : 도커 이미지에서 새로운 컨테이너를 생성합니다. 그러나 즉시 실행되지는 않습니다 Docker start : 중지된 컨테이너를 시작합니다. docker create 명령을 사용하여 컨테이너를 만든 경우 이 명령으로 시작할 수 있습니다. Docker run : create와 start의 조합으로 새 컨테이너를 생성하고 시작합니다. docker run 명령은 로컬 시스템에서 이미지를 찾지 못하는 경우 Docker Hub에서 이미지를 가져와서 컨테이너를 생성하고 실행합니다. |
잘 뜨네요. 기쁩니다.
컨테이너를 실행했으니 내부로 들어가 봅시다.
3. Container 내부탐험
$ docker exec
root@ubuntu-focal:~# docker exec -it nginx /bin/bash
root@1303feec1720:/# hostname
root@1303feec1720:/# cat /etc/issue
...
root@1303feec1720:/# exit
root@ubuntu-focal:~# docker run -it -p 8090:80 --name=nginx80999 nginx:latest bash
코드 블럭 |
---|
# 내부장벽진입
root@ubuntu-focal:~# docker exec -it nginx /bin/bash
root@1303feec1720:/#
# 진입완료
# 컨테이너의 hostname을 알아봅시다
root@1303feec1720:/# hostname
1303feec1720
root@1303feec1720:/# cat /etc/issue
Debian GNU/Linux 12 \n \l
root@57c8f50ce8c5:/#
# Shell을 빠져나오려면 Ctrl + D 혹은 exit를 입력합니다.
# 혹시docker를 daemon으로 설치하지 않고, 아래와같이 bash로 들어갔다면
root@ubuntu-focal:~# docker run -it -p 8090:80 --name=nginx80999 nginx:latest bash
# exit로 나왔을 경우 container 도 쉘 종료메세지(exit 0)을 받고 자연스럽게 종료 되기때문에 docker start [컨테이더 ID ] 명령어로 재시작 혹은 ctrl+ pq 로 실행을 유지한 채 터미널로 빠져 나올 수 있습니다. |
4. Image 삭제
: 보통은 이미지를 삭제하기 전 컨테이너를 먼저 삭제한 후 진행됩니다.
코드 블럭 |
---|
# docker rm 명령어를 통해 삭제합니다
# 컨테이너 삭제
root@ubuntu-focal:~# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest eea7b3dcba7e 2 weeks ago 187MB
root@ubuntu-focal:~# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
9eb7bfa20030 nginx:latest "/docker-entrypoint.…" About a minute ago Up About a minute 0.0.0.0:8090->80/tcp, :::8090->80/tcp nginx80999
1303feec1720 nginx:latest "/docker-entrypoint.…" 42 minutes ago Up 42 minutes 0.0.0.0:8080->80/tcp, :::8080->80/tcp nginx
root@ubuntu-focal:~# docker rm nginx
Error response from daemon: You cannot remove a running container 1303feec17205609e6303e72831084babeaebdfaec3bf9bf0f6f4e4b39082dd1. Stop the container before attempting removal or force remove
root@ubuntu-focal:~# docker rm nginx80999
Error response from daemon: You cannot remove a running container 9eb7bfa20030ad9c3e28b56ea437075b617b5b062894b409843177c764a2cbf0. Stop the container before attempting removal or force remove
# 어라? 삭제가 안되네요
# 먼저 중지를 해줍니다.
root@ubuntu-focal:~# docker kill nginx
nginx
# 다시삭제를 해봅니다.
root@ubuntu-focal:~# docker rm nginx
nginx
root@ubuntu-focal:~# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
# 잘 삭제가 되네요
|
이미지도 지워버립시다.
코드 블럭 |
---|
# docker rmi 명령어를 통해 이미지를 삭제해줍니다.
root@ubuntu-focal:~# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest eea7b3dcba7e 2 weeks ago 187MB
# $ docker rmi nginx:latest 혹은 $ docker rmi [ 이미지 ID ]
root@ubuntu-focal:~# docker rmi nginx
Untagged: nginx:latest
Untagged: nginx@sha256:104c7c5c54f2685f0f46f3be607ce60da7085da3eaa5ad22d3d9f01594295e9c
Deleted: sha256:eea7b3dcba7ee47c0d16a60cc85d2b977d166be3960541991f3e6294d795ed24
root@ubuntu-focal:~# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE |
컨테이너를 삭제하기 전 이미지를 삭제할 경우 -f옵션으로 한꺼번에 삭제할 수 있습니다.
$ docker rmi -f [이미지 ID]
> 컨테이너도 강제삭제
docker hub 로그인 방법
코드 블럭 |
---|
root@ubuntu-focal:~# docker login
Login with your Docker ID to push and pull images from Docker Hub. If you don't have a Docker ID, head over to https://hub.docker.com to create one.
Username: dncs0725
Password:
WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store
Login Succeeded
|
Dockerfile 만들기
도커를 설치하고 컨테이너를 실행해봤으니 이제는 도커 이미지를 만들고 서버에 배포해볼 차례!
도커 개념에서도 다뤄봤듯이, 도커는 도커 파일을 가지고 도커 이미지를 만들게 되는데요,
다시 한번 말씀드리자면, Docker File이란 Docker Image를 만들기 위한 여러가지 명령어의 집합입니다.
예를 들어, 일반 서버로 웹서버를 구축시 아래와 같은 작업이 필요합니다.
ubuntu 설치
패키지 업데이트
nginx 설치
경로설정 (필요한 경우)
코드 블럭 |
---|
## 1. ubuntu 설치 & 2. 패키지 업데이트
# 테스트 ubuntu 서버를 사용하였기 때문에 패키지 업데이트를 먼저 합니다.
root@ubuntu-focal:~# apt-update
## 3. nginx 설치
root@ubuntu-focal:~# apt install nginx
#4. 설치 확인
root@ubuntu-focal:~# nginx -v
nginx version: nginx/1.18.0 (Ubuntu)
#5. 설치파일 경로
root@ubuntu-focal:~# cd /etc/nginx
root@ubuntu-focal:/etc/nginx# pwd
/etc/nginx
|
여기서 잠깐
저희는 nginx를 패키지를 통하여 설치 하였기에 Default directory가 /etc/nginx 아래에 위치하게 됩니다.
직접 compile한 경우에 경로는 /usr/local/nginx/conf 혹은 /use/local/etc/nginx 에 위치하고 있습니다.
그래도 경로가 없다 한다면 다음의 명령어를 통해 찾을 수 있습니다.
코드 블럭 |
---|
root@ubuntu-focal:~# sudo find / -name nginx.conf
/etc/nginx/nginx.conf
|
경로설정 (필요한 경우)
코드 블럭 |
---|
root@ubuntu-focal:/etc/nginx# ls
conf.d koi-utf modules-available proxy_params sites-enabled win-utf
fastcgi.conf koi-win modules-enabled scgi_params snippets
fastcgi_params mime.types nginx.conf sites-available uwsgi_params
# 기본적인 환경 설정 파일 정보는 sites-available/default 이곳에 있습니다.
# 따라서 웹서버의 루트 디렉토리 변경 등의 작업이 필요하다면 이곳에 들어가 작업하시면 됩니다.
root@ubuntu-focal:/etc/nginx# vim sites-available/default
|
저는 테스트이기 때문에 따로 경로 설정은 안하고 Default로 두었습니다.
코드 블럭 |
---|
# index.html 를 만든 후 찍어 봅니다.
root@ubuntu-focal:/etc/nginx# cat index.html
Hello~~ docker
root@ubuntu-focal:/etc/nginx# cp index.html /var/www/html/
root@ubuntu-focal:/etc/nginx# service nginx restart
root@ubuntu-focal:/etc/nginx# curl localhost
Hello~~ docker |
...
이제는 이런 한땀한땀 구축한 명령어를 토대로 docker file을 만들어 보겠습니다.
ubuntu 설치
패키지 업데이트 apt update
nginx 설치 apt install nginx
경로설정 (필요한 경우) cd /etc/nginx
코드 블럭 |
---|
cd /home/vagrant |
cat Dockerfile
코드 블럭 |
---|
FROM ubuntu:20.04
MAINTAINER Hojin kim "khoj@osci.kr"
RUN apt update
RUN apt install -y nginx
WORKDIR /etc/nginx
CMD ["nginx", "-g", "daemon off;"]
EXPOSE 80
|
docker file이 거의 흡사하게 작성된 것을 보실 수 있습니다. 아마 도커파일에 있는 내용들이 생소하실 여러분(저를 포함)을 위해 하나하나 뜯어 보도록 할까요?
FROM ubuntu:20.04
-> 기반으로 할 이미지를 가져옵니다. 여기에서는 ubuntu 20.04버전의 이미지를 가져오겠습니다.
MAINTAINER Hojin kim "khoj@osci.kr"
-> 작성자의 정보를 기입해줍니다.
RUN apt update
-> RUN이라는 명령어를 통하여 쉘 스크립트를 실행하여 줍니다.
RUN apt install -y nginx
-> 도커 빌드 중에는 키보드를 입력할 수 없기에 [-y] 옵션을 넣어줍니다.
WORKDIR /etc/nginx
-> 이후 CMD 명령어가 실행 할 경로로 먼저 이동을 해 줍니다.
CMD ["nginx", "-g", "daemon off;"]
-> nginx를 백그라운드로 실행합니다
EXPOSE 80
-> 80번 포트를 오픈하여 웹서버에 정상적으로 접근할 수 있게 합니다.
아직까지 Dockerfile 명령어들이 익숙치 않으시죠? 아니라고 해도 명령어들은 좀더 나눠서 알아보겠습니다.
명렁어 | 내용 | 예시 |
|
---|---|---|---|
FROM | – 베이스 이미지를 지정해줍니다. | FROM <image>:<tag> |
|
-> 베이스 이미지는 반드시 지정해줘야하며, 버전정보는 latest보다는 구체적인 버전을 지정해주는것이 좋습니다.
RUN | – 직접적으로 쉘 스크립트 내에서 실행 될 명령어 앞에 적어줍니다. | RUN <command> |
|
-> 실질적으로 가장 많이 쓰이는 명령어 입니다
CMD | – 도커가 실행될 때 실행할 명령어를 정의해줍니다. | CMD [“executable”, “param”, “param”] |
|
-> 도커 빌드시에는 실행되지 않으며, 여러개의 CMD 명령어가 존재할 경우 가장 마지막 명령어만 실행 됩니다. CMD nginx 라고 입력하면 nginx 서버를 구동시키게 됩니다.
WORKDIR | – 이후 명령어가 작업할 디렉토리로 이동합니다 | WORKDIR /path |
|
-> 명령어(RUN, CMD ) 등이 실행될 디렉토리를 설정합니다. 각 명령어는 줄마다 초기화가 되기 때문에 ‘RUN cd /path’ 로 경로를 잡아줘도 다음줄에선 다시 위치가 초기화가 됩니다. 같은 디렉토리에서 계속 작업하기 위하여 WORKDIR을 사용해줍니다.
COPY | – 파일이나 디렉토리를 이미지로 복사합니다 | COPY <src> <dst> | COPY . /usr/src/app |
-> 일반적으로 소스를 복사하는데 사용합니다
ADD | – COPY와 비슷하게 복사를 위해 사용합니다 | ADD <src> <dst> | ADD . /usr/src/app |
-> COPY명령어와 비슷하게 소스를 복사하는데 사용하지만 차이점은 ADD같은경우 압축파일이 있을 경우 자동으로 압축을 해제하면서 복사됩니다.
EXPOSE | – 공개 하고자 하는 포트를 지정해줍니다 | EXPOSE <port> |
|
-> 호스트와 연결해줄 포트를 지정해주며, 여러개의 포트를 지정할 수 있습니다.
이 밖에 사용되는 ENV
, VOLUME
같은 명령어는 공식문서 를 참고 바랍니다
Build 하기
코드 블럭 |
---|
docker build --force-rm --tag mynginx:0.1 .
|
–force-rm : 기존에 존재하는 image를 삭제합니다.
–tag : 태그를 설정해줍니다.
코드 블럭 |
---|
root@ubuntu-focal:~# docker build --tag mynginx:0.1 .
DEPRECATED: The legacy builder is deprecated and will be removed in a future release.
Install the buildx component to build images with BuildKit:
https://docs.docker.com/go/buildx/
Sending build context to Docker daemon 17.41kB
Step 1/7 : FROM ubuntu:20.04
20.04: Pulling from library/ubuntu
edaedc954fb5: Pull complete
Digest: sha256:33a5cc25d22c45900796a1aca487ad7a7cb09f09ea00b779e3b2026b4fc2faba
Status: Downloaded newer image for ubuntu:20.04
---> 6df894023726
Step 2/7 : MAINTAINER Hojin kim "khoj@osci.kr"
---> Running in b568cf60d414
Removing intermediate container b568cf60d414
---> 7f72532b3e72
Step 3/7 : RUN apt update
---> Running in 44b39e24a339
WARNING: apt does not have a stable CLI interface. Use with caution in scripts.
Get:1 http://security.ubuntu.com/ubuntu focal-security InRelease [114 kB]
Fetched 28.2 MB in 7s (3951 kB/s)
Reading package lists...
Building dependency tree...
Reading state information...
All packages are up to date.
Removing intermediate container 44b39e24a339
---> b00de74eef37
Step 4/7 : RUN apt install -y nginx
---> Running in 1b206d0758d4
Processing triggers for libc-bin (2.31-0ubuntu9.9) ...
Removing intermediate container 1b206d0758d4
---> 6cd8450ed504
Step 5/7 : WORKDIR /etc/nginx
---> Running in 7b4c7f8dc6b1
Removing intermediate container 7b4c7f8dc6b1
---> 3d5f4b3e96f6
Step 6/7 : CMD ["nginx", "-g", "daemon off;"]
---> Running in 5c78083ddaed
Removing intermediate container 5c78083ddaed
---> 80a706657ecf
Step 7/7 : EXPOSE 80
---> Running in 829ebedc357a
Removing intermediate container 829ebedc357a
---> 03de8991a4f8
Successfully built 03de8991a4f8
Successfully tagged mynginx:0.1
# 이미지확인
root@ubuntu-focal:~# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
mynginx 0.1 03de8991a4f8 About a minute ago 178MB
ubuntu 20.04 6df894023726 5 weeks ago 72.8MB
|
빌드가 완료되어 Docker Image가 만들어진 것을 확인할 수 있는데요 이 빌드가 되는 과정들도 또 하나하나 살펴보도록 하겠습니다.
빌드과정을 요약하면 다음과 같습니다.
코드 블럭 |
---|
Sending build context to Docker daemon 17.41kB <--- [1]
Step 1/7 : FROM ubuntu:20.04 <--- [2]
20.04: Pulling from library/ubuntu <--- [3]
---> 6df894023726 <--- [4]
Step 2/7 : MAINTAINER Hojin kim "khoj@osci.kr"" <--- [5]
---> Running in b568cf60d414 <--- [6]
Removing intermediate container b568cf60d414 <--- [7]
---> 7f72532b3e72 <--- [8]
Step 3/7 : RUN apt update <--- [9]
---> Running in 1e6d817f7aa0
...
successfully built 03de8991a4f8 <--- [10]
|
[1] Sending build context to Docker daemon 17.41kB
도커는 서버 클라이언트 구조이기 때문에 작업할 도커파일들(build context)을 도커서버(daemon)으로 전송해줍니다.
[2] Step 1/7 : FROM ubuntu:20.04
빌드할 도커파일의 제일 윗줄부터 한줄한줄 실행하여 줍니다.
[3] 20.04: Pulling from library/ubuntu
ubuntu라는 이미지를 repository에서 다운받는 작업을 합니다 기본적으로 DockerHub Repository를 사용하고 있으며 사용자가 별도의 저장소를 지정할 수 있습니다.
[4] ---> 6df894023726
다운받은 ubuntu 이미지의 ID를 출력해줍니다.
[5] Step 2/7 : MAINTAINER Hojin kim "khoj@osci.kr""
도커파일의 두번째 명령어를 실행해줍니다.
[6] ---> Running in b568cf60d414
도커는 이미지 형태로 저장하기 때문에 바로위에서 실행한 우분투 이미지 ‘6df894023726’를 기반으로 임시 컨테이너 ‘b568cf60d414’ 를 만듭니다.
[7],[8]Removing intermediate container b568cf60d414
---> 7f72532b3e72
임시로 실행했던 컨테이너 ‘b568cf60d414’를 삭제해주고 새로운 이미지 ‘7f72532b3e72’를 만듭니다.
[9] Step 3/7 : RUN apt update
도커파일에 작성하였던 다음줄의 명령어를 실행해줍니다. 이전 단계 에서처럼 _전에 만들어진 이미지를 기반으로 임시 컨테이너를 만들어 명령어를 실행하고 이를 또 다른 이미지로 저장을 한 후 임시 컨테이너는 삭제_하여줍니다. 이러한 과정을 도커파일의 마지막 명령줄까지 반복합니다.
[10] successfully built 03de8991a4f8
최종적으로 만들어진 이미지ID를 멋지게 출력해줍니다.
좀 전에 빌드했던 도커파일을 다시 빌드하게 되면 처음 빌드했을 때 보다 훨씬 빨라지게 되는데요 그 이유는, 명령어를 실행할 때 이미지 위에 레이어를 추가하는 형태로 저장을 하게 되고 재 빌드를 하게 되면 기존에 저장된 이미지를 그대로 캐시처럼 사용하여 빌드 하기 때문입니다. (변경된 사항이 없다면)
코드 블럭 |
---|
# 재빌드
root@ubuntu-focal:~# docker build --tag mynginx:0.1 .
Sending build context to Docker daemon 17.41kB
Step 1/7 : FROM ubuntu:20.04
---> 6df894023726
Step 2/7 : MAINTAINER Hojin kim "khoj@osci.kr"
---> Using cache
---> 7f72532b3e72
Step 3/7 : RUN apt update
---> Using cache
---> b00de74eef37
Step 4/7 : RUN apt install -y nginx
---> Using cache
---> 6cd8450ed504
Step 5/7 : WORKDIR /etc/nginx
---> Using cache
---> 3d5f4b3e96f6
Step 6/7 : CMD ["nginx", "-g", "daemon off;"]
---> Using cache
---> 80a706657ecf
Step 7/7 : EXPOSE 80
---> Using cache
---> 03de8991a4f8
Successfully built 03de8991a4f8
Successfully tagged mynginx:0.1
|
이러한 도커빌드 원리를 이해하고 있으면 도커파일을 만들 때 효과적으로 만드실 수 있습니다.
그리고 그 history는 아래에서 확인할수 있습니다.
코드 블럭 |
---|
root@ubuntu-focal:~# docker history mynginx:0.1
IMAGE CREATED CREATED BY SIZE COMMENT
03de8991a4f8 9 minutes ago /bin/sh -c #(nop) EXPOSE 80 0B
80a706657ecf 9 minutes ago /bin/sh -c #(nop) CMD ["nginx" "-g" "daemon… 0B
3d5f4b3e96f6 9 minutes ago /bin/sh -c #(nop) WORKDIR /etc/nginx 0B
6cd8450ed504 9 minutes ago /bin/sh -c apt install -y nginx 59.3MB
b00de74eef37 10 minutes ago /bin/sh -c apt update 45.7MB
7f72532b3e72 10 minutes ago /bin/sh -c #(nop) MAINTAINER Hojin kim "kho… 0B
6df894023726 5 weeks ago /bin/sh -c #(nop) CMD ["/bin/bash"] 0B
<missing> 5 weeks ago /bin/sh -c #(nop) ADD file:233702cd816c07bc9… 72.8MB
<missing> 5 weeks ago /bin/sh -c #(nop) LABEL org.opencontainers.… 0B
<missing> 5 weeks ago /bin/sh -c #(nop) LABEL org.opencontainers.… 0B
<missing> 5 weeks ago /bin/sh -c #(nop) ARG LAUNCHPAD_BUILD_ARCH 0B
<missing> 5 weeks ago /bin/sh -c #(nop) ARG RELEASE 0B |
참고로 명렁어를 주르륵 나열하기보단 최대한 간결하고 ‘&&’ 명령어를 이용해 줄여서 적어주는것이 좋습니다! (스토리지 엔진에 따라 이미지 개수가 제한되는 경우도 있기때문)
###빌드한 이미지는 각 서버에 어떻게 배포할까요?
도커는 이미지를 각각의 서버에 복사하는 방법 대신 저장소(Registry)를 이용합니다.
여기서 이미지를 저장소에 업로드할때 ‘push’ 명령어를 사용하고, 각 서버에서 저장소에 올려져있는 이미지를 가져올때 ‘pull’이라는 명령어를 사용합니다.
저번시간에 tag에 대하여 스르륵 지나갔었는데 이미지 이야기를 하는김에 같이 다뤄보도록 하겠습니다.
이미지 태그에 관하여
‘docker tag <옵션> <이미지 이름>:<태그> <저장소 주소, 사용자명>/<이미지이름>:<태그>’ 굉장히 복잡해 보입니다…
저장소 주소는 기본적으로 Docker hub를 바라보고 있고, 사용자 ID를 지정해주지 않으면 기본으로 library를 사용합니다.
즉, ‘<저장소 주소, 사용자명>/<이미지이름>:<태그>’는 http://docker.io/library/nginx = library/nginx = nginx 이렇게 추릴수도 있습니다.
이미지 이름 변경
‘docker tag <reponame>:<old_name> <new_reponame>:<new_name> -> 이름을 변경한다기 보다는 복제라고 보는게 더 맞습니다.
코드 블럭 |
---|
root@ubuntu-focal:~# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
mynginx 0.1 03de8991a4f8 11 minutes ago 178MB
ubuntu 20.04 6df894023726 5 weeks ago 72.8MB
root@ubuntu-focal:~# docker tag mynginx:0.1 mynginx:0.2
root@ubuntu-focal:~# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
mynginx 0.1 03de8991a4f8 12 minutes ago 178MB
mynginx 0.2 03de8991a4f8 12 minutes ago 178MB
ubuntu 20.04 6df894023726 5 weeks ago 72.8MB
root@ubuntu-focal:~# |
...
3. 컨테이너 Orchestration
Container Orchestration은 애플리케이션을 구성하고 있는 수십 또는 수백 개의 컨테이너와 호스트들을 배포하고 관리하기 위한 도구입니다.
...