docker
ㅇ 도커의 개념
Develope | Ship | Run |
도커 이미지를 빌드(생성) | 레지스트리에 도커 이미지 저장 | 도커 컨테이너를 실행 |
- Docker - Build, Ship, and Run Any App, Anywhere // docker.com
- Docker is an open platform for developing, shipping, and running applications. //docker.com
- 배경 : 리눅스 서버 1대를 나눠쓰고, 오케스트레이션할 필요성에 대한 니즈
. 시초 : 2013년도 PyCon "The future of Linux container" (리눅스 컨테이너를 쓰기 편하게 만들기)
- 특징 : Liuxe base(리눅스 컨테이터 기술인 LXC기반), stateless, immutable, scalabe, go언어, 64 bit OS only
Directory/Lib/IP를 공유
레거시 장비의 OS 사용과 달리 실시간성으로 프로세스를 관리하는 수준으로 편리하게 활용 가능
ㅇ 도커의 구성 요소
구성 요소 | 설명 | 특징 |
도커 이미지 | 컨테이너 실행 위한 리소스의 계층적 조합의 손쉽게 설치 가능 파일 | layered |
도커 컨테이너 | 도커 이미지의 실행 인스턴스 | 동일 이미지로 여러 컨테이너 생성 |
도커 가상화 기술 | 리눅스 커널 기능인 namespaces, cgroups 기술 활용 | 독립공간 격리성, 리소스 제어 |
도커 엔진 | 도커 운영을 모두 감당 도커 서버(데몬)와 도커 클라이언트(CLI)의 구성 |
REST API 통신 |
도커 머신 | 도커 런타임 환경 | 격리 환경 |
도커 서버(데몬) | 도커 이미지를 빌드, 저장, 실행 | 리소스 제어 |
도커 클라이언트 | 도커 데몬과 통신하여 도커 아키텍처 사용 | 원격 관리의 편리성 |
namespaces | 독립된 격리 공간을 제공 6가지 namespace : mnt,pid,net,ips,uts,user |
격리성 |
cgroups | 리소스 제어 : mem, cpu, i/o, network, device - 자원할당, 우선순위 지정, 거부, 관리, 모니터링 |
계층화, 효율성 |
도커 컴포즈 | yaml 포맷으로 작성되며 여러 개의 컨테이너의 실행을 한 번에 관리 | 통합성, 편리성 |
도커 레지스트리 | 도커 이미지 저장소 | 배포 환경 |
도커 허브 (도커 클라우드) |
도커 이미지 중앙 저장소 | 클라우드화 |
도커 스토어 | 도커 이미지 매매 및 무료 배포 공간 | 거래 |
도커 스웜 | 도커 엔진 그룹을 단일 가상 도커 엔진으로 묶는 클러스터링 기능 제공 | 클러스터링 |
ㅇ 도커 이미지 배포
kubernetes 가 defacto 표준
ㅇ 도커 명령어
구분 | 명령어 |
도커 시작하기 | $ docker version # cf. docker --version $ docker info # docker system info $ docker --help $ docker run hello-world $ docker images $ docker ps # cf. docker ps -a $ docker-machine ls |
도커 이미지&컨테이너 명령 |
docker image <command> [image-name] $> docker image [pull | push] docker container run <docker-image-name> <command> $> docker container run ubuntu:latest /bin/echo 'Hello world' $> docker ps -a $> docker system df $> docker image ls $> docker pull <docker-image-name[:tag-name]> $> docker pull nginx $> docker container rm webserver $> docker container attach ub #> exit(kill) or Ctrl+P, Ctrl+Q (detach) $> docker container exec -it ub /bin/cat /etc/hosts $> docker start webserver $> docker container port oracle $> docker container rename webserver nginxserver |
도커 컨테이너로 들어가기 |
$> docker container run -it --name "test1" centos /bin/cal $> docker container run -it --name "cosh" centos /bin/bash $> docker container run -it --restart=always --name "centsh" centos /bin/bash $> docker container run -itd --name ubsh ubuntu bash $> docker container attach ubsh # Ctrl+P, Ctrl+Q |
MySQL 설치 |
$> docker search mysql $> docker pull mysql:5.7 $> docker run -d -p 3306:3306 -e MYSQL_ROOT_PASSWORD=r! $> docker ps $> docker exec -it mysql5 bash #> mysql -u root -p |
도커 커밋 |
$> docker logs <container-id> # backup the container to image $> docker load < ~/backup/oracle.tar |
ㅇ 도커 command 옵션
docker run 옵션
-v | 호스트와 컨테이너의 디렉토리를 연결 (마운트) |
-e | 컨테이너 내에서 사용할 환경변수 설정 |
–name | 컨테이너 이름 설정 |
–rm | 프로세스 종료시 컨테이너 자동 제거 |
Options:
--config string Location of client config files (default
"/Users/jck/.docker")
-c, --context string Name of the context to use to connect to the
daemon (overrides DOCKER_HOST env var and
default context set with "docker context use")
-D, --debug Enable debug mode
-H, --host list Daemon socket(s) to connect to
-l, --log-level string Set the logging level
("debug"|"info"|"warn"|"error"|"fatal")
(default "info")
--tls Use TLS; implied by --tlsverify
--tlscacert string Trust certs signed only by this CA (default
"/Users/jck/.docker/ca.pem")
--tlscert string Path to TLS certificate file (default
"/Users/jck/.docker/cert.pem")
--tlskey string Path to TLS key file (default
"/Users/jck/.docker/key.pem")
--tlsverify Use TLS and verify the remote
-v, --version Print version information and quit
Management Commands:
app* Docker App (Docker Inc., v0.9.1-beta3)
builder Manage builds
buildx* Build with BuildKit (Docker Inc., v0.5.1-docker)
config Manage Docker configs
container Manage containers
context Manage contexts
image Manage images
manifest Manage Docker image manifests and manifest lists
network Manage networks
node Manage Swarm nodes
plugin Manage plugins
scan* Docker Scan (Docker Inc., v0.5.0)
secret Manage Docker secrets
service Manage services
stack Manage Docker stacks
swarm Manage Swarm
system Manage Docker
trust Manage trust on Docker images
volume Manage volumes
Commands:
attach Attach local standard input, output, and error streams to a running container
build Build an image from a Dockerfile
commit Create a new image from a container's changes
cp Copy files/folders between a container and the local filesystem
create Create a new container
diff Inspect changes to files or directories on a container's filesystem
events Get real time events from the server
exec Run a command in a running container
export Export a container's filesystem as a tar archive
history Show the history of an image
images List images
import Import the contents from a tarball to create a filesystem image
info Display system-wide information
inspect Return low-level information on Docker objects
kill Kill one or more running containers
load Load an image from a tar archive or STDIN
login Log in to a Docker registry
logout Log out from a Docker registry
logs Fetch the logs of a container
pause Pause all processes within one or more containers
port List port mappings or a specific mapping for the container
ps List containers
pull Pull an image or a repository from a registry
push Push an image or a repository to a registry
rename Rename a container
restart Restart one or more containers
rm Remove one or more containers
rmi Remove one or more images
run Run a command in a new container
save Save one or more images to a tar archive (streamed to STDOUT by default)
search Search the Docker Hub for images
start Start one or more stopped containers
stats Display a live stream of container(s) resource usage statistics
stop Stop one or more running containers
tag Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE
top Display the running processes of a container
unpause Unpause all processes within one or more containers
update Update configuration of one or more containers
version Show the Docker version information
wait Block until one or more containers stop, then print their exit codes
Run 'docker COMMAND --help' for more information on a command.
To get more help with docker, check out our guides at https://docs.docker.com/go/guides/