버전 비교

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

...

코드 블럭
$mkdir -p ~/vagrant/ubuntu
$cd ~/vagrant/ubuntu 
$vagrant init sysnet4admin/Ubuntu-k8s
$vagrant up

2.5.1. 기동 된 VM 확인

  1. vagrant 명령어로 확인

    1. $ vagrant box list

      image-20240514-034351.png
    2. 코드 블럭
      $ 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:~$

2.5.2. Image 가져오기

(1) docker image 저장소

...

  • 기본 개념에서와 같이 도커는 저장소(registry)에서 이미지를 가져와 사용을 합니다.

...

코드 블럭
# 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.5.3. 컨테이너 기동

(1) 현재 실행 중인 컨테이너 확인

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

...

정보

Docker create : 도커 이미지에서 새로운 컨테이너를 생성합니다. 그러나 즉시 실행되지는 않습니다

Docker start : 중지된 컨테이너를 시작합니다. docker create 명령을 사용하여 컨테이너를 만든 경우 이 명령으로 시작할 수 있습니다.

Docker run : create와 start의 조합으로 새 컨테이너를 생성하고 시작합니다. docker run 명령은 로컬 시스템에서 이미지를 찾지 못하는 경우 Docker Hub에서 이미지를 가져와서 컨테이너를 생성하고 실행합니다.

2.5.4. Container 내부 탐험

(1) exec 명령어를 이용한 컨테이너 접속

코드 블럭
root@ubuntu-focal:~# docker exec -it nginx /bin/bash
root@1303feec1720:/# hostname
root@1303feec1720:/# cat /etc/issue
root@1303feec1720:/# exit

# 혹시docker를 daemon으로 설치하지 않고, 아래와같이 bash로 들어갔다면
# exit로 나왔을 경우 container 도 쉘 종료메세지(exit 0)을 받고 자연스럽게 종료 되기때문에 docker start [컨테이더 ID ] 명령어로 재시작 혹은 ctrl+ pq 로 실행을 유지한 채 터미널로 빠져 나올 수 있습니다.
# docker run -it  -p 8090:80 --name=nginx80999 nginx:latest bash

...

2.5.5. 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

 

2.5.6. Linux 서버에 웹서버 구축

(1) ubuntu 설치 & 패키지 업데이트

코드 블럭
## 1. ubuntu 설치 & 2. 패키지 업데이트
root@ubuntu-focal:~# apt-update

...

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

2.5.7. Dockerfile을 통한 도커 이미지 생성

  • Docker File이란 Docker Image를 만들기 위한 여러가지 명령어의 집합

...

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

2.5.8. 이미지 Build

(1) 작성한 Dockerfile을 빌드합니다.

...

참고로 명렁어를 주르륵 나열하기보단 최대한 간결하고 ‘&&’ 명령어를 이용해 줄여서 적어주는것이 좋습니다! (스토리지 엔진에 따라 이미지 개수가 제한되는 경우도 있기때문)

...

2.5.9. 이미지 태그

(1) 이미지 이름 구조

  • 저장소 주소는 기본적으로 Docker hub를 바라보고 있고, 사용자 ID를 지정해주지 않으면 기본으로 library를 사용합니다.

  • docker pull 명령어 시, 모두 같은 동작을 의미합니다.

...