Docker Command 정리 #01
문서버전: 2018.02.20 v0.1
docker help 명령어 확인시 아래와 같은 명령어를 확인 할수 있습니다.
자주 사용하는 명령어 위주로 정리 하였습니다.
일부 내용의 오타가 있을수 있습니다. 🙂
옵션 부분의 경우 차후 정리할 예정입니다.
test@docker-test01:~$ docker help Usage: docker COMMAND A self-sufficient runtime for containers Options: --config string Location of client config files (default "/home/test/.docker") -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 "/home/test/.docker/ca.pem") --tlscert string Path to TLS certificate file (default "/home/test/.docker/cert.pem") --tlskey string Path to TLS key file (default "/home/test/.docker/key.pem") --tlsverify Use TLS and verify the remote -v, --version Print version information and quit Management Commands: config Manage Docker configs container Manage containers image Manage images network Manage networks node Manage Swarm nodes plugin Manage plugins secret Manage Docker secrets service Manage services swarm Manage Swarm system Manage Docker 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. test@docker-test01:~$
docker help Command 정리
docker $command $option 형식으로 사용합니다.
docker attach
Attach local standard input, output, and error streams to a running container
official page doc: https://docs.docker.com/engine/reference/commandline/attach/#override-the-detach-sequence
docker attach test1
test@docker-test02:~$ docker run -d --name topdemo ubuntu /usr/bin/top -b Unable to find image 'ubuntu:latest' locally latest: Pulling from library/ubuntu 1be7f2b886e8: Pull complete 6fbc4a21b806: Pull complete c71a6f8e1378: Pull complete 4be3072e5a37: Pull complete 06c6d2f59700: Pull complete Digest: sha256:e27e9d7f7f28d67aa9e2d7540bdc2b33254b452ee8e60f388875e5b7d9b2b696 Status: Downloaded newer image for ubuntu:latest ce15a2b8e919ab37b60113189f8c2547718fcbabeecce34224f3695b611e7bfe test@docker-test02:~$ docker attach 실행 test@docker-test02:~$ docker attach topdemo top - 09:55:13 up 1:40, 0 users, load average: 0.08, 0.05, 0.01 Tasks: 1 total, 1 running, 0 sleeping, 0 stopped, 0 zombie %Cpu(s): 0.7 us, 0.7 sy, 0.0 ni, 98.7 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st KiB Mem : 998340 total, 247164 free, 160772 used, 590404 buff/cache KiB Swap: 1048572 total, 1042460 free, 6112 used. 638368 avail Mem PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 1 root 20 0 36532 3064 2704 R 0.0 0.3 0:00.03 top top - 09:55:16 up 1:40, 0 users, load average: 0.08, 0.05, 0.01 Tasks: 1 total, 1 running, 0 sleeping, 0 stopped, 0 zombie %Cpu(s): 0.0 us, 0.0 sy, 0.0 ni,100.0 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st KiB Mem : 998340 total, 247164 free, 160772 used, 590404 buff/cache KiB Swap: 1048572 total, 1042460 free, 6112 used. 638368 avail Mem PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 1 root 20 0 36532 3064 2704 R 0.0 0.3 0:00.03 top
docker attach test2
test@docker-test02:~$ docker run --name ssh-server -d -p 12341:22 -v /home/test/ftp:/home/test/ftp ssh-server test@docker-test02:~$ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 210ec4045be4 ssh-server "/usr/sbin/sshd -D" 2 hours ago Up 2 seconds 0.0.0.0:12341->22/tcp ssh-server test@docker-test02:~$ test@docker-test02:~$ docker attach 210ec4045be4
docker attach 커맨드를 이용하여 ssh-server 컨테이너에 접속을 하였지만 접속이 안되는것처럼 보입니다.??
docker 명령어 입력마지막 부분에 /bin/bash 를 입력 하지 않을경우 위와같이 접속만 되어 있습니다.
Ctrl+\ 를 입력하여 attach를 종료 합니다.
종료후 아래와 같이 컨테이너가 종료 합니다.
test@docker-test02:~$ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES test@docker-test02:~$
Ctrl+ p q 입력시 아래와 같이 컨테이너 실행상태에서 나올수 있습니다.
test@docker-test02:~/ssh-server$ docker attach ssh-server read escape sequence test@docker-test02:~/ssh-server$ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 7576cad72333 ssh-server "/usr/sbin/sshd -D" 2 minutes ago Up 2 minutes 0.0.0.0:12341->22/tcp ssh-server test@docker-test02:~/ssh-server$
docker attach 로 컨테이너에 접속하기 위해서는 -d -it 옵션을 사용해야 합니다.
test@docker-test02:~$ docker run --name test -d -it debian Unable to find image 'debian:latest' locally latest: Pulling from library/debian 3e731ddb7fc9: Pull complete Digest: sha256:4fcd8c0b6f5e3bd44a3e63be259fd0c038476d432953d449ef34aedf16def331 Status: Downloaded newer image for debian:latest 3fd41406c5968d8e3c5fd56903a23d6de4d88b230bdf69cff9b3e13ceb8fd213 test@docker-test02:~$ docker attach test root@3fd41406c596:/#
-d 컨테이너를 생성하여 백그라운드에서 실행
-i 컨테이너 표준입력 열기
-t tty사용
docker build
Build an image from a Dockerfile
official page doc: https://docs.docker.com/engine/reference/commandline/build/
docker build test
test@docker-test02:~/nginx$ vi Dockerfile test@docker-test02:~/nginx$ docker build --tag nginx . ~중략 test@docker-test02:~/nginx$ docker images REPOSITORY TAG IMAGE ID CREATED SIZE nginx latest 80889b2672a1 50 seconds ago 208MB
Dockerfile 작성후 image 생성시 사용 합니다.
--tag 옵션으로 image의 tag를 생성 할수 있습니다.
docker commit
Create a new image from a container's changes
official page doc: https://docs.docker.com/engine/reference/commandline/commit/
docker commit test / git install
test@docker-test02:~/nginx$ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 7576cad72333 ssh-server "/usr/sbin/sshd -D" 32 minutes ago Up 32 minutes 0.0.0.0:12341->22/tcp ssh-server test@docker-test02:~/nginx$ docker exec -it ssh-server /bin/bash root@7576cad72333:/# apt-get install -y git ~중략 exit 를 입력한후 컨테이너에서 빠져 나옵니다. test@docker-test02:~/nginx$ docker commit ssh-server ssh-server:git sha256:64f7265d353e9a5a1fdb021c54205ffaae73ec0bd43a3f1cdf5cba510a3da93b test@docker-test02:~/nginx$ test@docker-test02:~$ docker images REPOSITORY TAG IMAGE ID CREATED SIZE ssh-server git 64f7265d353e 44 seconds ago 281MB
docker run 으로 실행후 git 명령어 실행
test@docker-test02:~$ docker run -it -d ssh-server:git /bin/bash 5da63c65e0a36398a78a64d7199008c779ad20dd7cf31947fd776928475316ee test@docker-test02:~$ docker exec -it ssh-server:git /bin/bash Error: No such container: ssh-server:git test@docker-test02:~$ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 5da63c65e0a3 ssh-server:git "/bin/bash" 24 seconds ago Up 24 seconds 22/tcp quirky_hamilton test@docker-test02:~$ docker exec -it 5da63c65e0a3 /bin/bash root@5da63c65e0a3:/# git usage: git [--version] [--help] [-C <path>] [-c name=value] [--exec-path[=<path>]] [--html-path] [--man-path] [--info-path] [-p | --paginate | --no-pager] [--no-replace-objects] [--bare] [--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>] <command> [<args>] These are common Git commands used in various situations: start a working area (see also: git help tutorial) clone Clone a repository into a new directory init Create an empty Git repository or reinitialize an existing one work on the current change (see also: git help everyday) add Add file contents to the index mv Move or rename a file, a directory, or a symlink reset Reset current HEAD to the specified state rm Remove files from the working tree and from the index examine the history and state (see also: git help revisions) bisect Use binary search to find the commit that introduced a bug grep Print lines matching a pattern log Show commit logs show Show various types of objects
docker commit 의 경우 컨테이너의 변경 사항을 새로운 이미지로 만드는 작업 이라고 보시면 됩니다.
docker cp
Copy files/folders between a container and the local filesystem
official page doc: https://docs.docker.com/engine/reference/commandline/cp/
docker cp test
ex) docker cp $컨테이너이름:$경로 $host경로
test@docker-test:~/ftp-server$ docker cp ftpd:/etc/pure-ftpd/pureftpd.passwd /home/test/ftp-server/ test@docker-test:~/ftp-server$ ll total 24 drwxrwxr-x 4 test test 4096 Feb 20 20:13 ./ drwxr-xr-x 4 test test 4096 Feb 19 21:43 ../ -rw-rw-r-- 1 test test 459 Feb 19 22:17 docker-compose.yml drwxrwxr-x 2 test test 4096 Feb 19 22:41 pure-ftpd/ -rw-rw-r-- 1 test test 76 Feb 19 22:41 pureftpd.passwd drwxrwxr-x 2 test test 4096 Feb 19 22:17 ssh-server/ test@docker-test:~/ftp-server$
docker cp의 경우 컨테이너의 파일을 카피 할때 사용 합니다.
docker create
Create a new container
official page doc: https://docs.docker.com/engine/reference/commandline/create/#specify-isolation-technology-for-container-isolation
docker create test
test@docker-test02:~/ssh-server$ docker create -i -t --name web-server httpd /bin/bash Unable to find image 'httpd:latest' locally latest: Pulling from library/httpd 4176fe04cefe: Pull complete d6c01cf91b98: Pull complete b7066921647a: Pull complete 643378aaba88: Pull complete 3c51f6dc6a3b: Pull complete 4f25e420c4cc: Pull complete ccdbe37da15c: Pull complete Digest: sha256:6e61d60e4142ea44e8e69b22f1e739d89e1dc8a2764182d7eecc83a5bb31181e Status: Downloaded newer image for httpd:latest c148af581e62e60f10bdf936953887c7c7bc8f812c1de722b7520550f5550ab2 test@docker-test02:~/ssh-server$ test@docker-test02:~/ssh-server$ docker images REPOSITORY TAG IMAGE ID CREATED SIZE ssh-server git 64f7265d353e 16 minutes ago 281MB nginx latest 80889b2672a1 38 minutes ago 208MB ssh-server latest da649966e69c About an hour ago 206MB httpd latest 01154c38b473 5 days ago 177MB
run 명령어의 경우 컨테이너를 만들고 실행하지만 create 의 경우 컨테이너 생성만 하며 실행하지 않습니다.
docker diff
Inspect changes to files or directories on a container's filesystem
official page doc: https://docs.docker.com/engine/reference/commandline/diff/
docker diff test
test@docker-test01:~$ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 4a9c504e3fc0 6aa9f4528408 "/usr/sbin/sshd -D" 3 hours ago Up 3 hours 0.0.0.0:12341->22/tcp ssh-server test@docker-test01:~$ docker diff 4a9c504e3fc0 C /home/test A /home/test/.cache A /home/test/.cache/motd.legal-displayed A /home/test/ftp C /run A /run/motd.dynamic A /run/sshd.pid C /run/utmp C /var/log/lastlog C /var/log/wtmp test@docker-test01:~$
diff 명령어로 컨테이너에서 변경된 파일을 확인 할수 있습니다.
A 추가된 파일 / D 삭제된 파일 / C 변경된 파일
docker events
Get real time events from the server
official page doc: https://docs.docker.com/engine/reference/commandline/events/
docker events test
테스트를 위하여 2개의 터미널이 필요합니다.
터미널1
test@docker-test01:~$ docker events
터미널2
test@docker-test01:~$ docker start ssh-server ssh-server test@docker-test01:~$
ssh-server 컨테이너 실행후
터미널1
test@docker-test01:~$ docker events 2018-02-20T20:29:20.559545172+09:00 network connect e6379e085e70251ff6d3aed56b526f0fac2d5cb35a62125ec35f9db043f88013 (container=4a9c504e3fc066c451c037b35041b1308e181b121cd54b3f2fea28b703c98276, name=bridge, type=bridge) 2018-02-20T20:29:20.825386119+09:00 container start 4a9c504e3fc066c451c037b35041b1308e181b121cd54b3f2fea28b703c98276 (image=ssh-server, name=ssh-server)
리얼타임으로 이벤트를 확인할수 있습니다.
docker exec
Run a command in a running container
official page doc: https://docs.docker.com/engine/reference/commandline/exec/
docker exec test
test@docker-test02:~$ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 5da63c65e0a3 ssh-server:git "/bin/bash" 31 minutes ago Up 31 minutes 22/tcp quirky_hamilton test@docker-test02:~$ docker exec -it 5da63c65e0a3 /bin/bash root@5da63c65e0a3:/#
docker exec는 실행중인 컨테이너에 접속할때 사용합니다.
docker export
Export a container's filesystem as a tar archive
official page doc: https://docs.docker.com/engine/reference/commandline/export/
docker export test
test@docker-test02:~$ docker export ssh-server > ./ssh-server.tar test@docker-test02:~$ ls Dockerfile ftp nginx ssh-server ssh-server.tar test@docker-test02:~$
컨테이너 백업시 사용합니다.
docker history
Show the history of an image
official page doc: https://docs.docker.com/engine/reference/commandline/history/
docker history test
test@docker-test01:~$ docker history ssh-server IMAGE CREATED CREATED BY SIZE COMMENT 7497e5839808 4 hours ago /usr/sbin/sshd -D 293kB 6aa9f4528408 4 hours ago /bin/sh -c #(nop) CMD ["/usr/sbin/sshd" "-D… 0B 42ebcc23b6f4 4 hours ago /bin/sh -c #(nop) EXPOSE 22 0B 6e1b50e948a4 4 hours ago /bin/sh -c echo "export VISIBLE=now" >> /etc… 594B 6520e9fab9c9 4 hours ago /bin/sh -c #(nop) ENV NOTVISIBLE=in users p… 0B 559b0ee95543 4 hours ago /bin/sh -c apt-get update && apt-get install… 94.6MB f98d236d73eb 4 hours ago /bin/sh -c #(nop) MAINTAINER Sven Dowideit … 0B 0458a4468cbc 3 weeks ago /bin/sh -c #(nop) CMD ["/bin/bash"] 0B <missing> 3 weeks ago /bin/sh -c mkdir -p /run/systemd && echo 'do… 7B <missing> 3 weeks ago /bin/sh -c sed -i 's/^#\s*\(deb.*universe\)$… 2.76kB <missing> 3 weeks ago /bin/sh -c rm -rf /var/lib/apt/lists/* 0B <missing> 3 weeks ago /bin/sh -c set -xe && echo '#!/bin/sh' > /… 745B <missing> 3 weeks ago /bin/sh -c #(nop) ADD file:a3344b835ea6fdc56… 112MB test@docker-test01:~$
image history 를 출력합니다.
docker images
List images
official page doc: https://docs.docker.com/engine/reference/commandline/images/
docker images test
test@docker-test:~$ docker images REPOSITORY TAG IMAGE ID CREATED SIZE ftp/pure-ftpd 14.04 75c73f446597 22 hours ago 435MB <none> <none> 6a6688153895 23 hours ago 435MB ssh-server latest 1e5966c6bdf0 23 hours ago 206MB ubuntu 16.04 0458a4468cbc 3 weeks ago 112MB ubuntu 14.04 dc4491992653 3 weeks ago 222MB test@docker-test:~$
docker image 정보를 출력합니다.
docker import
Import the contents from a tarball to create a filesystem image
official page doc: https://docs.docker.com/engine/reference/commandline/import/
docker import test
test@docker-test01:~$ cat ssh-server.tar | docker import - ssh-server sha256:3f3f63beac844f0c2e806f2a4cc22457dd612abefd8417eabd9dbd1de5a92ecc test@docker-test01:~$ docker images REPOSITORY TAG IMAGE ID CREATED SIZE ssh-server latest 3f3f63beac84 2 seconds ago 253MB test@docker-test01:~$
export 한 tar 파일로 images 를 생성 합니다.
docker info
Display system-wide information
official page doc: https://docs.docker.com/engine/reference/commandline/info/
docker info test
test@docker-test02:~$ docker info Containers: 5 Running: 1 Paused: 0 Stopped: 4 Images: 21 Server Version: 18.02.0-ce Storage Driver: overlay2 Backing Filesystem: extfs Supports d_type: true Native Overlay Diff: true Logging Driver: json-file Cgroup Driver: cgroupfs Plugins: Volume: local Network: bridge host macvlan null overlay Log: awslogs fluentd gcplogs gelf journald json-file logentries splunk syslog Swarm: inactive Runtimes: runc Default Runtime: runc Init Binary: docker-init containerd version: 9b55aab90508bd389d7654c4baf173a981477d55 runc version: 9f9c96235cc97674e935002fc3d78361b696a69e init version: 949e6fa Security Options: apparmor seccomp Profile: default Kernel Version: 4.4.0-62-generic Operating System: Ubuntu 16.04.3 LTS OSType: linux Architecture: x86_64 CPUs: 2 Total Memory: 974.9MiB Name: docker-test02 ID: QAGI:PK3E:CG7L:3D73:UQJ3:UP4P:LZTZ:2PZP:3GBS:ORWS:FL36:EWWJ Docker Root Dir: /var/lib/docker Debug Mode (client): false Debug Mode (server): false Registry: https://index.docker.io/v1/ Labels: Experimental: false Insecure Registries: 127.0.0.0/8 Live Restore Enabled: false WARNING: No swap limit support test@docker-test02:~$
docker 정보를 출력 합니다.
docker inspect
Return low-level information on Docker objects
official page doc: https://docs.docker.com/engine/reference/commandline/inspect/
docker inspect test
test@docker-test01:~$ docker inspect ssh-server [ { "Id": "sha256:3f3f63beac844f0c2e806f2a4cc22457dd612abefd8417eabd9dbd1de5a92ecc", "RepoTags": [ "ssh-server:latest" ], "RepoDigests": [], "Parent": "", "Comment": "Imported from -", "Created": "2018-02-20T11:52:52.28045397Z", "Container": "", "ContainerConfig": { "Hostname": "", "Domainname": "", "User": "", "AttachStdin": false, "AttachStdout": false, "AttachStderr": false, "Tty": false, "OpenStdin": false, "StdinOnce": false, "Env": null, "Cmd": null, "Image": "", "Volumes": null, "WorkingDir": "", "Entrypoint": null, "OnBuild": null, "Labels": null }, "DockerVersion": "18.02.0-ce", "Author": "", "Config": { "Hostname": "", "Domainname": "", "User": "", "AttachStdin": false, "AttachStdout": false, "AttachStderr": false, "Tty": false, "OpenStdin": false, "StdinOnce": false, "Env": null, "Cmd": null, "Image": "", "Volumes": null, "WorkingDir": "", "Entrypoint": null, "OnBuild": null, "Labels": null }, "Architecture": "amd64", "Os": "linux", "Size": 253405442, "VirtualSize": 253405442, "GraphDriver": { "Data": { "MergedDir": "/var/lib/docker/overlay2/6c47d31e2d5ff00a9fb4676f595a33fd45afaa6592c50cb069d1777df6bd4616/merged", "UpperDir": "/var/lib/docker/overlay2/6c47d31e2d5ff00a9fb4676f595a33fd45afaa6592c50cb069d1777df6bd4616/diff", "WorkDir": "/var/lib/docker/overlay2/6c47d31e2d5ff00a9fb4676f595a33fd45afaa6592c50cb069d1777df6bd4616/work" }, "Name": "overlay2" }, "RootFS": { "Type": "layers", "Layers": [ "sha256:3f277380640a29287b45210df57c9c6ea7711a363a593128e9c0c2fec50b91b8" ] }, "Metadata": { "LastTagTime": "2018-02-20T20:52:52.283195652+09:00" } } ] test@docker-test01:~$
image 정보 확인시 사용합니다.
이미지ID / 생성일 / Docker 버전 / 이미지 생성자 / CPU 확인할수 있습니다.
docker kill
Kill one or more running containers
official page doc: https://docs.docker.com/engine/reference/commandline/kill/
docker kill test2
test@docker-test:~$ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 74a223f30014 ftp/pure-ftpd:14.04 "/bin/sh -c '/usr/sb…" About an hour ago Up About an hour 0.0.0.0:21->21/tcp, 0.0.0.0:20000-20099->20000-20099/tcp ftpd b76d16b5f4b4 ssh-server "/usr/sbin/sshd -D" About an hour ago Up About an hour 0.0.0.0:12341->22/tcp ssh-server test@docker-test:~$ docker kill ssh-server ssh-server test@docker-test:~$ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 74a223f30014 ftp/pure-ftpd:14.04 "/bin/sh -c '/usr/sb…" About an hour ago Up About an hour 0.0.0.0:21->21/tcp, 0.0.0.0:20000-20099->20000-20099/tcp ftpd test@docker-test:~$
docker kill test2
test@docker-test:~/ftp-server$ docker kill ftpd ssh-server ftpd ssh-server test@docker-test:~/ftp-server$ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES test@docker-test:~/ftp-server$
docker kill 명령어로 컨테이너에 kill 시그널을 보낼수 있습니다.
하나 또는 하나이상의 컨테이를 kill 시킬수 있습니다.
docker load
Load an image from a tar archive or STDIN
official page doc: https://docs.docker.com/engine/reference/commandline/load/
docker load test
test@docker-test02:~$ docker load -i ssh-server.tar 3f277380640a: Loading layer [==================================================>] 264.1MB/264.1MB Loaded image: ssh-server:latest test@docker-test02:~$ docker images REPOSITORY TAG IMAGE ID CREATED SIZE ssh-server latest 3f3f63beac84 26 minutes ago 253MB test@docker-test02:~$
tar -> docker image로 변환 합니다.?
docker login
Log in to a Docker registry
official page doc: https://docs.docker.com/engine/reference/commandline/login/
//차후테스트
docker 저장소에 로그인합니다.
docker logout
Log out from a Docker registry
official page doc: https://docs.docker.com/engine/reference/commandline/logout/
//차후테스트
docker 저장소에서 로그아웃합니다.
docker logs
Fetch the logs of a container
official page doc: https://docs.docker.com/engine/reference/commandline/logs/
//차후테스트
컨테이너 로그를 출력합니다.
docker pause
Pause all processes within one or more containers
official page doc: https://docs.docker.com/engine/reference/commandline/pause/
docker pause test
test@docker-test01:~/ssh-server$ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES d2269ec836fd ssh-server "/usr/sbin/sshd -D" 3 minutes ago Up 3 minutes 0.0.0.0:12341->22/tcp ssh-server test@docker-test01:~/ssh-server$ docker pause ssh-server ssh-server test@docker-test01:~/ssh-server$ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES d2269ec836fd ssh-server "/usr/sbin/sshd -D" 6 minutes ago Up 6 minutes (Paused) 0.0.0.0:12341->22/tcp ssh-server test@docker-test01:~/ssh-server$
컨테이너 내의 모든 프로세스 일시정지
docker port
List port mappings or a specific mapping for the container
official page doc: https://docs.docker.com/engine/reference/commandline/port/
docker port test
test@docker-test01:~/ssh-server$ docker port ssh-server 22/tcp -> 0.0.0.0:12341 test@docker-test01:~/ssh-server$
특정컨테이너의 port 연결 정보를 확인 합니다.
docker ps
List containers
official page doc: https://docs.docker.com/engine/reference/commandline/ps/
docker ps test
test@docker-test01:~/ssh-server$ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES d2269ec836fd ssh-server "/usr/sbin/sshd -D" 12 minutes ago Up 12 minutes 0.0.0.0:12341->22/tcp ssh-server test@docker-test01:~/ssh-server$
컨테이너 정보를 확인 합니다.
docker pull
Pull an image or a repository from a registry
official page doc: https://docs.docker.com/engine/reference/commandline/pull/
docker pull test
test@docker-test01:~$ docker images REPOSITORY TAG IMAGE ID CREATED SIZE ssh-server latest f1c017c1bfcf 34 minutes ago 206MB ubuntu 16.04 0458a4468cbc 3 weeks ago 112MB test@docker-test01:~$ docker pull ubuntu:latest latest: Pulling from library/ubuntu Digest: sha256:e27e9d7f7f28d67aa9e2d7540bdc2b33254b452ee8e60f388875e5b7d9b2b696 Status: Downloaded newer image for ubuntu:latest test@docker-test01:~$ docker images REPOSITORY TAG IMAGE ID CREATED SIZE ssh-server latest f1c017c1bfcf 34 minutes ago 206MB ubuntu 16.04 0458a4468cbc 3 weeks ago 112MB ubuntu latest 0458a4468cbc 3 weeks ago 112MB test@docker-test01:~$
images 저장소에서 image를 down 합니다.
docker push
Push an image or a repository to a registry
official page doc: https://docs.docker.com/engine/reference/commandline/push/
docker push test
//차후테스트
docker hub 에 이미지를 등록합니다.
docker rename
Rename a container
official page doc: https://docs.docker.com/engine/reference/commandline/rename/
docker rename test
test@docker-test01:~$ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES d2269ec836fd ssh-server "/usr/sbin/sshd -D" 23 minutes ago Up 23 minutes 0.0.0.0:12341->22/tcp ssh-server test@docker-test01:~$ docker rename ssh-server sshd test@docker-test01:~$ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES d2269ec836fd ssh-server "/usr/sbin/sshd -D" 23 minutes ago Up 23 minutes 0.0.0.0:12341->22/tcp sshd test@docker-test01:~$
컨테이너의 이름을 변경 합니다.
docker restart
Restart one or more containers
official page doc: https://docs.docker.com/engine/reference/commandline/restart/
docker restart test
test@docker-test01:~$ docker restart sshd sshd test@docker-test01:~$ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES d2269ec836fd ssh-server "/usr/sbin/sshd -D" 25 minutes ago Up 3 seconds 0.0.0.0:12341->22/tcp sshd test@docker-test01:~$
컨테이너를 재시작 합니다.
docker rm
Remove one or more containers
official page doc: https://docs.docker.com/engine/reference/commandline/rm/
docker rm test
test@docker-test01:~$ docker stop sshd sshd test@docker-test01:~$ docker rm sshd sshd test@docker-test01:~$ docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES test@docker-test01:~$
컨테이너를 삭제 합니다.
docker rmi
Remove one or more images
official page doc: https://docs.docker.com/engine/reference/commandline/rmi/
docker rmi test
test@docker-test01:~$ docker images REPOSITORY TAG IMAGE ID CREATED SIZE ubuntu latest 0458a4468cbc 3 weeks ago 112MB test@docker-test01:~$ docker rmi 0458a4468cbc Untagged: ubuntu:latest Untagged: ubuntu@sha256:e27e9d7f7f28d67aa9e2d7540bdc2b33254b452ee8e60f388875e5b7d9b2b696 Deleted: sha256:0458a4468cbceea0c304de953305b059803f67693bad463dcbe7cce2c91ba670 Deleted: sha256:77e6ddba346d8ad1e436256f6373dede5af4002006981b7d4116c561c759cefa Deleted: sha256:8db758ab2fdb54da0aec53aeac876934337e6170f5a8c8872b3d4171e3d465b7 Deleted: sha256:a7fc6b405fe8ef71edfa6163d1dc9f1cb1df426049eefaa7d388e9df21a061ad Deleted: sha256:5a3e35538f7f2e2727c8ac92f08c30002b9e8a77737de0dab91244344d59f69b Deleted: sha256:ff986b10a018b48074e6d3a68b39aad8ccc002cdad912d4148c0f92b3729323e test@docker-test01:~$
images 를 삭제 합니다.
docker run
Run a command in a new container
official page doc: https://docs.docker.com/engine/reference/run/
docker run test
test@docker-test02:~/ssh-server$ docker run --name ssh-server -d -p 12341:22 -v /home/test/ftp:/home/test/ftp ssh-server eef4f1176e28dca616b2b4ba7a3b59c6722f8a7f8a3d079c901b31c8a00f60ba test@docker-test02:~/ssh-server$
컨테이너를 실행 합니다.
docker save
Save one or more images to a tar archive (streamed to STDOUT by default)
official page doc: https://docs.docker.com/engine/reference/commandline/save/
docker save test
test@docker-test01:~$ docker save -o ssh-server.tar ssh-server test@docker-test01:~$ ls ftp ssh-server ssh-server.tar test@docker-test01:~$
docker images 를 tar 파일로 저장합니다.
docker search
Search the Docker Hub for images
official page doc: https://docs.docker.com/engine/reference/commandline/search/
docker search test
test@docker-test01:~$ docker search nginx NAME DESCRIPTION STARS OFFICIAL AUTOMATED nginx Official build of Nginx. 7971 [OK] jwilder/nginx-proxy Automated Nginx reverse proxy for docker con… 1276 [OK] richarvey/nginx-php-fpm Container running Nginx + PHP-FPM capable of… 517 [OK] jrcs/letsencrypt-nginx-proxy-companion LetsEncrypt container to use with nginx as p… 312 [OK] kong Open-source Microservice & API Management la… 158 [OK] webdevops/php-nginx Nginx with PHP-FPM 97 [OK] kitematic/hello-world-nginx A light-weight nginx container that demonstr… 95 bitnami/nginx Bitnami nginx Docker Image 44 [OK] zabbix/zabbix-web-nginx-mysql Zabbix frontend based on Nginx web-server wi… 43 [OK] linuxserver/nginx An Nginx container, brought to you by LinuxS… 33 1and1internet/ubuntu-16-nginx-php-phpmyadmin-mysql-5 ubuntu-16-nginx-php-phpmyadmin-mysql-5 26 [OK] tobi312/rpi-nginx NGINX on Raspberry Pi / armhf 17 [OK] wodby/drupal-nginx Nginx for Drupal container image 9 [OK] webdevops/nginx Nginx container 8 [OK] blacklabelops/nginx Dockerized Nginx Reverse Proxy Server. 8 [OK] nginxdemos/nginx-ingress NGINX Ingress Controller for Kubernetes 8 centos/nginx-18-centos7 Platform for running nginx 1.8 or building n… 6 1science/nginx Nginx Docker images that include Consul Temp… 4 [OK] nginxdemos/hello NGINX webserver that serves a simple page co… 3 [OK] pebbletech/nginx-proxy nginx-proxy sets up a container running ngin… 2 [OK] behance/docker-nginx Provides base OS, patches and stable nginx f… 2 [OK] centos/nginx-112-centos7 Platform for running nginx 1.12 or building … 2 travix/nginx NGinx reverse proxy 1 [OK] toccoag/openshift-nginx Nginx reverse proxy for Nice running on same… 1 [OK] mailu/nginx Mailu nginx frontend 0 [OK] test@docker-test01:~$
Docker 이미지를 검색 합니다.
docker start
Start one or more stopped containers
official page doc: https://docs.docker.com/engine/reference/commandline/start/
docker start test
test@docker-test02:~/ssh-server$ docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES eef4f1176e28 ssh-server "/usr/sbin/sshd -D" 16 minutes ago Exited (0) 3 seconds ago ssh-server test@docker-test02:~/ssh-server$ docker start ssh-server ssh-server test@docker-test02:~/ssh-server$
정지된 컨테이너를 실행 합니다.
docker stats
Display a live stream of container(s) resource usage statistics
official page doc: https://docs.docker.com/engine/reference/commandline/stats/
docker stats test
test@docker-test02:~/ssh-server$ docker stats ssh-server CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS eef4f1176e28 ssh-server 0.00% 716KiB / 974.9MiB 0.07% 648B / 0B 0B / 0B 1
컨테이너의 자원 사용량을 확인 합니다.
docker stop
Stop one or more running containers
official page doc: https://docs.docker.com/engine/reference/commandline/stop/
docker stop test
test@docker-test02:~/ssh-server$ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES eef4f1176e28 ssh-server "/usr/sbin/sshd -D" 20 minutes ago Up 4 minutes 0.0.0.0:12341->22/tcp ssh-server test@docker-test02:~/ssh-server$ docker stop ssh-server ssh-server test@docker-test02:~/ssh-server$
컨테이너를 정지합니다.
docker tag
Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE
official page doc: https://docs.docker.com/engine/reference/commandline/tag/
docker tag test
test@docker-test02:~/ssh-server$ docker images REPOSITORY TAG IMAGE ID CREATED SIZE ssh-server latest 8ee8efce9736 40 minutes ago 206MB <none> <none> 3f3f63beac84 2 hours ago 253MB ubuntu 16.04 0458a4468cbc 3 weeks ago 112MB test@docker-test02:~/ssh-server$ docker tag 0458a4468cbc nginx-test test@docker-test02:~/ssh-server$ docker images REPOSITORY TAG IMAGE ID CREATED SIZE ssh-server latest 8ee8efce9736 41 minutes ago 206MB <none> <none> 3f3f63beac84 2 hours ago 253MB ubuntu 16.04 0458a4468cbc 3 weeks ago 112MB nginx-test latest 0458a4468cbc 3 weeks ago 112MB test@docker-test02:~/ssh-server$ test@docker-test02:~/ssh-server$ docker images REPOSITORY TAG IMAGE ID CREATED SIZE ssh-server latest 8ee8efce9736 45 minutes ago 206MB <none> <none> 3f3f63beac84 2 hours ago 253MB nginx-test 0.1 0458a4468cbc 3 weeks ago 112MB nginx-test latest 0458a4468cbc 3 weeks ago 112MB ubuntu 16.04 0458a4468cbc 3 weeks ago 112MB test@docker-test02:~/ssh-server$
docker top
Display the running processes of a container
official page doc: https://docs.docker.com/engine/reference/commandline/top/
docker top test
test@docker-test02:~/ssh-server$ docker top ssh-server UID PID PPID C STIME TTY TIME CMD root 17478 17460 0 23:23 ? 00:00:00 /usr/sbin/sshd -D test@docker-test02:~/ssh-server$
컨테이너의 실행중인 프로세스를 표시합니다.
docker unpause
Unpause all processes within one or more containers
official page doc: https://docs.docker.com/engine/reference/commandline/unpause/
docker unpause test
test@docker-test02:~/ssh-server$ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES eef4f1176e28 ssh-server "/usr/sbin/sshd -D" About an hour ago Up 2 minutes (Paused) 0.0.0.0:12341->22/tcp ssh-server test@docker-test02:~/ssh-server$ docker unpause ssh-server ssh-server test@docker-test02:~/ssh-server$ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES eef4f1176e28 ssh-server "/usr/sbin/sshd -D" About an hour ago Up 2 minutes 0.0.0.0:12341->22/tcp ssh-server test@docker-test02:~/ssh-server$
docker pause 상태에서 복귀 합니다.
docker update
Update configuration of one or more containers
official page doc: https://docs.docker.com/engine/reference/commandline/update/
docker update test
//차후테스트
컨테이너 설정을 업데이트 합니다.
docker version
Show the Docker version information
official page doc: https://docs.docker.com/engine/reference/commandline/version/
docker version test
test@docker-test01:~$ docker version Client: Version: 18.02.0-ce API version: 1.36 Go version: go1.9.3 Git commit: fc4de44 Built: Wed Feb 7 21:16:33 2018 OS/Arch: linux/amd64 Experimental: false Orchestrator: swarm Server: Engine: Version: 18.02.0-ce API version: 1.36 (minimum version 1.12) Go version: go1.9.3 Git commit: fc4de44 Built: Wed Feb 7 21:15:05 2018 OS/Arch: linux/amd64 Experimental: false test@docker-test01:~$
docker version 을 출력합니다.
docker wait
Block until one or more containers stop, then print their exit codes
official page doc: https://docs.docker.com/engine/reference/commandline/wait/
docker wait test
터미널 1
test@docker-test02:~/ssh-server$ docker wait ssh-server
docker wait ssh-server 명령어를 실행후 대기합니다.
터미널2
test@docker-test02:~$ docker kill ssh-server ssh-server
터미널1
test@docker-test02:~/ssh-server$ docker wait ssh-server 137 test@docker-test02:~/ssh-server$
docker wait 실행시 컨테이너가 종료할때까지 대기하다가 종료 코드를 출력 합니다.
Comments