Docker CLI (Command Line Interface) ?
- Docker 컨테이너와 상호 작용하고 command line에서 직접 컨테이너 생태계의 다양한 측면을 관리할 수 있는 강력한 도구
- CLI를 사용하면 컨테이너 생성, 시작, 중지, 삭제는 물론 컨테이너 이미지, 네트워크, 볼륨 관리 등의 작업을 효율적으로 처리 가능
- Docker CLI는 컨테이너와 해당 리소스를 관리할 수 있는 강력하고 유연한 옵션을 제공
Docker 설치 확인
$ docker --version
Docker version 20.10.17, build 100c701
Docker 명령어 사용법 확인
$ docker COMMAND --help
$ docker run --help
Usage: docker run [OPTIONS] IMAGE [COMMAND] [ARG...]
Run a command in a new container
Options:
...
Docker container 관리
build
도커파일의 이미지 빌드
$ docker build [OPTIONS] PATH | URL | -
Options:
- -t, --tag list : Name and optionally a tag in the 'name:tag' format
- --build-arg list : Set build-time variables
pull
레지스트리에서 이미지나 저장소를 가져오기
$ docker pull [OPTIONS] NAME[:TAG|@DIGEST]
push
레지스트리에 이미지나 저장소를 업로드
$ docker push [OPTIONS] NAME[:TAG]
image
도커 이미지 관리
$ docker image COMMAND
COMMAND:
- build : Build an image from a Dockerfile
- history : Show the history of an image
- inspect : Display detailed information on one or more images
- prune : Remove unused images
- pull : Pull an image or a repository from a registry
- push : Push an image or a repository to a registry
- ls : List images
- rm : Remove one or more images
run
새 컨테이너에서 명령 실행
$ docker run [OPTIONS] IMAGE [COMMAND] [ARG...]
Options:
- -d, --detach : Run container in background and print container ID
- -i, --interactive : Keep STDIN open even if not attached
- -p, --publish list : Publish a container's port(s) to the host
- -t, --tty : Allocate a pseudo-TTY
- -v, --volume list : Bind mount a volume
- --rm : Automatically remove the container when it exits
- --name string : Assign a name to the container
ps
컨테이너 목록 표시
$ docker ps [OPTIONS]
Options:
- -a, --all : Show all containers (default shows just running)
- -f, --filter filter : Filter output based on conditions provided
- --format string : Pretty-print containers using a Go template
- -n, --last int : Show n last created containers (includes all states) (default -1)
- -l, --latest : Show the latest created container (includes all states)
- -q, --quiet : Only display container IDs
exec
실행 중인 컨테이너에서 명령 실행
docker exec [OPTIONS] CONTAINER COMMAND [ARG...]
Options:
- -d, --detach Detached mode: run command in the background
- -i, --interactive Keep STDIN open even if not attached
- -t, --tty Allocate a pseudo-TTY
stop
실행 중인 컨테이너 하나 이상을 중지
$ docker stop [OPTIONS] CONTAINER [CONTAINER...]
Options:
- -t, --time int Seconds to wait for stop before killing it (default 10)
kill
실행 중인 컨테이너 하나 이상 종료 (강제 종료)
$ docker kill [OPTIONS] CONTAINER [CONTAINER...]
Options:
- -s, --signal string Signal to send to the container (default "KILL")
rm
하나 이상의 컨테이너를 제거
$ docker rm [OPTIONS] CONTAINER [CONTAINER...]
Options:
- -f, --force Force the removal of a running container (uses SIGKILL)
Docker container 상태 모니터링
stats
컨테이너 리소스 사용 통계 표시
$ docker stats [OPTIONS] [CONTAINER...]
- 라이브 데이터 스트림을 반환 (나올때: command+p+q)
Options:
- --no-stream : 스트리밍 통계를 비활성화하고 첫 번째 결과만 출력
$ docker stats nginx01 --no-stream
CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS
19e92c486f42 nginx01 0.00% 4.305MiB / 3.841GiB 0.11% 4.34kB / 1.97kB 0B / 12.3kB 5
top
컨테이너의 실행중인 프로세스 표시
$ docker top CONTAINER [ps OPTIONS]
$ docker top nginx01
UID PID PPID C STIME TTY TIME CMD
root 5459 5434 0 07:22 ? 00:00:00 nginx: master process nginx -g daemon off;
uuidd 5511 5459 0 07:22 ? 00:00:00 nginx: worker process
uuidd 5512 5459 0 07:22 ? 00:00:00 nginx: worker process
uuidd 5513 5459 0 07:22 ? 00:00:00 nginx: worker process
uuidd 5514 5459 0 07:22 ? 00:00:00 nginx: worker process
logs
컨테이너의 로그 보기
$ docker logs [OPTIONS] CONTAINER
Options:
- -f , --follow : 실시간으로 로그 출력
$ docker logs nginx01
/docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
/docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
/docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
10-listen-on-ipv6-by-default.sh: info: Getting the checksum of /etc/nginx/conf.d/default.conf
10-listen-on-ipv6-by-default.sh: info: Enabled listen on IPv6 in /etc/nginx/conf.d/default.conf
/docker-entrypoint.sh: Sourcing /docker-entrypoint.d/15-local-resolvers.envsh
/docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
/docker-entrypoint.sh: Launching /docker-entrypoint.d/30-tune-worker-processes.sh
/docker-entrypoint.sh: Configuration complete; ready for start up
2024/11/14 07:22:05 [notice] 1#1: using the "epoll" event method
2024/11/14 07:22:05 [notice] 1#1: nginx/1.27.2
2024/11/14 07:22:05 [notice] 1#1: built by gcc 12.2.0 (Debian 12.2.0-14)
2024/11/14 07:22:05 [notice] 1#1: OS: Linux 5.10.104-linuxkit
2024/11/14 07:22:05 [notice] 1#1: getrlimit(RLIMIT_NOFILE): 1048576:1048576
2024/11/14 07:22:05 [notice] 1#1: start worker processes
2024/11/14 07:22:05 [notice] 1#1: start worker process 29
2024/11/14 07:22:05 [notice] 1#1: start worker process 30
2024/11/14 07:22:05 [notice] 1#1: start worker process 31
2024/11/14 07:22:05 [notice] 1#1: start worker process 32
172.17.0.1 - - [14/Nov/2024:07:22:23 +0000] "GET / HTTP/1.1" 200 615 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36" "-"
172.17.0.1 - - [14/Nov/2024:07:41:34 +0000] "GET / HTTP/1.1" 304 0 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36" "-"
* docker cli reference
https://docs.docker.com/reference/cli/docker/
'! > docker' 카테고리의 다른 글
docker compose (0) | 2025.05.29 |
---|---|
docker network (0) | 2025.04.15 |
docker volume, bind mounts (0) | 2025.04.12 |
Dockerfile (0) | 2025.04.04 |
Docker 설치 (MacOS) (0) | 2022.09.05 |