버전 비교

  • 이 줄이 추가되었습니다.
  • 이 줄이 삭제되었습니다.
  • 서식이 변경되었습니다.

...

코드 블럭
# 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

이미지를 가져왔으니 이제 실행시켜봐야죠!

 

...

 

...

4. Run Container

docker ps

코드 블럭
# docker ps 라는 명령어로 현재 실행중인 컨테이너를 확인합니다.
# docker ps -a -> 중지된 컨테이너까지 모두 출력
root@ubuntu-focal:~# docker ps
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES

...

잘 뜨네요. 기쁩니다.

컨테이너를 실행했으니 내부로 들어가 봅시다.

...

5. Container 내부탐험

$ docker exec

root@ubuntu-focal:~# docker exec -it nginx /bin/bash

 

root@1303feec1720:/# hostnamehostnam5

root@1303feec1720:/# cat /etc/issue

...

코드 블럭
# 내부장벽진입
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 로 실행을 유지한 채 터미널로 빠져 나올 수 있습니다.

...

6. Image 삭제

: 보통은 이미지를 삭제하기 전 컨테이너를 먼저 삭제한 후 진행됩니다.

...

코드 블럭
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

 

7. Dockerfile 만들기

도커를 설치하고 컨테이너를 실행해봤으니 이제는 도커 이미지를 만들고 서버에 배포해볼 차례!

...

코드 블럭
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

...

이 밖에 사용되는 ENV VOLUME 같은 명령어는 공식문서 를 참고 바랍니다

Build 하기

코드 블럭
docker build --force-rm --tag mynginx:0.1 .

...

여기서 이미지를 저장소에 업로드할때 ‘push’ 명령어를 사용하고, 각 서버에서 저장소에 올려져있는 이미지를 가져올때 ‘pull’이라는 명령어를 사용합니다.
저번시간에 tag에 대하여 스르륵 지나갔었는데 이미지 이야기를 하는김에 같이 다뤄보도록 하겠습니다.

5. 이미지 태그에 관하여

‘docker tag <옵션> <이미지 이름>:<태그> <저장소 주소, 사용자명>/<이미지이름>:<태그>’ 굉장히 복잡해 보입니다…

...

코드 블럭
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은 애플리케이션을 구성하고 있는 수십 또는 수백 개의 컨테이너와 호스트들을 배포하고 관리하기 위한 도구입니다.

...