[Docker] 기초정리 (2)

|

컨테이너

- 하나의 isolate 된 application

- node.js / mysql / 이런식으로 각각 분리되어 있으므로 독립적으로 배포해서 관리 가능

- 컨테이너 이미지는 여러개의 layer로 구성되어서 하나의 application으로 실행될 수 있게함.

- layer는 uuid로 이루어져 있음

컨테이너? 컨테이너 이미지?

- 컨테이너 이미지 : 저장소에 저장되어 있는 개별 image (file)

- 컨테이너 : 컨테이너 이미지를 실행(동작)하는 상태 (process)

 

컨테이너 동작방식

hub.docker.com → 수십만개의 컨테이너가 존재
docker search nginx // nginx가 존재하는지 hub에서 찾아주세요
docker pull nginx:latest // nginx 이미지를 가져옴(다운로드)

// run: 이미지화시킴 (run 대신 create, start 도 있음)
docker run -d --name web -p 80:80 nginx:latest // docker platform(dockerd)에 실행시킴

 

용어정리

- Docker Host: 도커 데몬이 동작되고 있는 시스템

- Docker Daemon: systemctl start docker 으로 실행한 도커

- Docker Client Command: docker

- Docker Hub: 도커닷컴에서 제공해주는 허브

- Container Images: 이미지 레이어 별로 저장

- Container: 하나의 프로세스 상태로 실행되는 것

 


// 도커 시작
systemctl start docker

// configure docker to start on boot with systemd
systemctl enable docker.service
systemctl enable containerd.service

// disable
systemctl disable docker.service
systemctl disable containerd.service

// docker daemon 중지
sudo service docker stop

// docker 데이타 삭제
sudo rm -rf /var/run/docker
sudo rm /var/run/docker.*

// 서비스 재시작
sudo service docker start

// 컨테이너 시작
docker start mycontainer

// 도커 상태확인
docker info

// 도커 서비스 상태 확인
systemctl status docker 

// docker 저장소 구성
root@docker-ubuntu:/var/lib/docker# ls -l
합계 44
drwx--x--x 4 root root 4096  6월 15 15:49 buildkit
drwx--x--- 2 root root 4096  6월 15 15:49 containers
drwx------ 3 root root 4096  6월 15 15:49 image
drwxr-x--- 3 root root 4096  6월 15 15:49 network
drwx--x--- 3 root root 4096  6월 16 15:48 overlay2 // ------> 이미지가 저장되는 위치
drwx------ 4 root root 4096  6월 15 15:49 plugins
drwx------ 2 root root 4096  6월 16 15:48 runtimes
drwx------ 2 root root 4096  6월 15 15:49 swarm
drwx------ 2 root root 4096  6월 16 15:48 tmp
drwx------ 2 root root 4096  6월 15 15:49 trust
drwx-----x 2 root root 4096  6월 16 15:48 volumes

// 이미지 다운로드
docker pull nginx

// 다운로드 받으면 아래와 같이 이미지가 생성됨
guru@docker-ubuntu:~$ docker images
REPOSITORY   TAG       IMAGE ID       CREATED      SIZE
nginx        latest    eb4a57159180   2 days ago   187MB

// 도커 실행
// `web` : name
// `80` : port
// `nginx` : repository name 
docker run --name web -d -p 80:80 nginx

// 현재 동작중인 도커 프로세스 확인
$ docker ps
CONTAINER ID   IMAGE     COMMAND                  CREATED         STATUS         PORTS                               NAMES
3c0b095d7a57   nginx     "/docker-entrypoint.…"   7 minutes ago   Up 7 minutes   0.0.0.0:80->80/tcp, :::80->80/tcp   web

// curl 명령어로 접속 확인
curl localhost:80

// `web` 동작중지
docker stop web

// `web` 컨테이너 삭제
docker rm web

// `nginx` 이미지 삭제
docker rmi nginx

'IT Infra' 카테고리의 다른 글

[Docker] mysql 설치  (0) 2023.06.28
[Docker] docker run vs. docker start  (0) 2023.06.28
[Docker] command 입력방법  (0) 2023.06.16
[Ubuntu] SELinux 설치  (0) 2023.06.16
리눅스(Linux), 커널(Kernel), 우분투(Ubuntu)  (0) 2023.06.15
And