1. 程式人生 > 其它 >效能環境之docker操作指南2(全網最全)

效能環境之docker操作指南2(全網最全)

docker [OPTIONS] command

  1. Usage: docker [OPTIONS] COMMAND [arg...]

  2. docker daemon [ --help | ... ]

  3. docker [ -h | --help | -v | --version ]

  4. A self-sufficient runtime for containers.

  5. Options:

  6. --config=~/.docker Location of client config files

  7. -D, --debug=false Enable debug mode

  8. -H, --host=[] Daemon socket(s) to connect to

  9. -h, --help=false Print usage

  10. -l, --log-level=info Set the logging level

  11. --tls=false Use TLS; implied by --tlsverify

  12. --tlscacert=~/.docker/ca.pem Trust certs signed only by this CA

  13. --tlscert=~/.docker/cert.pem Path to TLS certificate file

  14. --tlskey=~/.docker/key.pem Path to TLS key file

  15. --tlsverify=false Use TLS and verify the remote

  16. -v, --version=false Print version information and quit

attach

Attach to a running container
將終端依附到容器上

  1. Usage: docker attach [OPTIONS] CONTAINER

  2. Attach to a running container

  3. --help=false Print usage

  4. --no-stdin=false Do not attach STDIN

  5. --sig-proxy=true Proxy all received signals to the process

build

  1. Usage: docker build [OPTIONS] PATH | URL | -

  2. Build an image from a Dockerfile

  3. --build-arg=[] Set build-time variables

  4. --cpu-shares=0 CPU shares (relative weight)

  5. --cgroup-parent= Optional parent cgroup for the container

  6. --cpu-period=0 Limit the CPU CFS (Completely Fair Scheduler) period

  7. --cpu-quota=0 Limit the CPU CFS (Completely Fair Scheduler) quota

  8. --cpuset-cpus= CPUs in which to allow execution (0-3, 0,1)

  9. --cpuset-mems= MEMs in which to allow execution (0-3, 0,1)

  10. --disable-content-trust=true Skip image verification

  11. -f, --file= Name of the Dockerfile (Default is 'PATH/Dockerfile')

  12. --force-rm=false Always remove intermediate containers

  13. --help=false Print usage

  14. -m, --memory= Memory limit

  15. --memory-swap= Total memory (memory + swap), '-1' to disable swap

  16. --no-cache=false Do not use cache when building the image

  17. --pull=false Always attempt to pull a newer version of the image

  18. -q, --quiet=false Suppress the verbose output generated by the containers

  19. --rm=true Remove intermediate containers after a successful build

  20. -t, --tag= Repository name (and optionally a tag) for the image

  21. --ulimit=[] Ulimit options

通過Dockerfile建立映象。具體見以後的使用中。

commit

  1. Usage: docker commit [OPTIONS] CONTAINER [REPOSITORY[:TAG]]

  2. Create a new image from a container's changes

  3. -a, --author= Author (e.g., "John Hannibal Smith <[email protected]>")

  4. -c, --change=[] Apply Dockerfile instruction to the created image

  5. --help=false Print usage

  6. -m, --message= Commit message

  7. -p, --pause=true Pause container during commit

通過容器建立本地映象.
可自定義tag,如docker commit dc806ee0bf86 web:v1
不指定tag的情況下預設tag為latest

  1. root@ubuntu:~# docker commit dc806ee0bf86 test

  2. 1e488386876e14ef3e930a98ec0bb49de1890963e2e979069f9f4d87f89f4959

cp

  1. Usage: docker cp [OPTIONS] CONTAINER:PATH LOCALPATH|-

  2. docker cp [OPTIONS] LOCALPATH|- CONTAINER:PATH

  3. Copy files/folders between a container and the local filesystem

  4. Use '-' as the source to read a tar archive from stdin and extract it to a directory destination in a container.

  5. Use '-' as the destination to stream a tar archive of a container source to stdout.

容器和宿主機之間相互copy檔案
1.將容器:/data/a.txt複製到本地當前目錄

  1. $ docker cp 87cb69be18bb:/data/a.txt ./

2.將本地檔案複製到容器:/data/backup目錄下

  1. $ docker cp helpdocker.tgz 87cb69be18bb:/data/backup/

3.將本地目錄複製到容器:/data/backup目錄下

  1. $ docker cp data 87cb69be18bb:/data/backup

create

  1. Usage: docker create [OPTIONS] IMAGE [COMMAND] [ARG...]

  2. Create a new container

  3. -a, --attach=[] Attach to STDIN, STDOUT or STDERR

  4. --add-host=[] Add a custom host-to-IP mapping (host:ip)

  5. --blkio-weight=0 Block IO (relative weight), between 10 and 1000

  6. --cpu-shares=0 CPU shares (relative weight)

  7. --cap-add=[] Add Linux capabilities

  8. --cap-drop=[] Drop Linux capabilities

  9. --cgroup-parent= Optional parent cgroup for the container

  10. --cidfile= Write the container ID to the file

  11. --cpu-period=0 Limit CPU CFS (Completely Fair Scheduler) period

  12. --cpu-quota=0 Limit CPU CFS (Completely Fair Scheduler) quota

  13. --cpuset-cpus= CPUs in which to allow execution (0-3, 0,1)

  14. --cpuset-mems= MEMs in which to allow execution (0-3, 0,1)

  15. --device=[] Add a host device to the container

  16. --disable-content-trust=true Skip image verification

  17. --dns=[] Set custom DNS servers

  18. --dns-opt=[] Set DNS options

  19. --dns-search=[] Set custom DNS search domains

  20. -e, --env=[] Set environment variables

  21. --entrypoint= Overwrite the default ENTRYPOINT of the image

  22. --env-file=[] Read in a file of environment variables

  23. --expose=[] Expose a port or a range of ports

  24. --group-add=[] Add additional groups to join

  25. -h, --hostname= Container host name

  26. --help=false Print usage

  27. -i, --interactive=false Keep STDIN open even if not attached

  28. --ipc= IPC namespace to use

  29. --kernel-memory= Kernel memory limit

  30. -l, --label=[] Set meta data on a container

  31. --label-file=[] Read in a line delimited file of labels

  32. --link=[] Add link to another container

  33. --log-driver= Logging driver for container

  34. --log-opt=[] Log driver options

  35. --lxc-conf=[] Add custom lxc options

  36. -m, --memory= Memory limit

  37. --mac-address= Container MAC address (e.g. 92:d0:c6:0a:29:33)

  38. --memory-reservation= Memory soft limit

  39. --memory-swap= Total memory (memory + swap), '-1' to disable swap

  40. --memory-swappiness=-1 Tuning container memory swappiness (0 to 100)

  41. --name= Assign a name to the container

  42. --net=default Set the Network for the container

  43. --oom-kill-disable=false Disable OOM Killer

  44. -P, --publish-all=false Publish all exposed ports to random ports

  45. -p, --publish=[] Publish a container's port(s) to the host

  46. --pid= PID namespace to use

  47. --privileged=false Give extended privileges to this container

  48. --read-only=false Mount the container's root filesystem as read only

  49. --restart=no Restart policy to apply when a container exits

  50. --security-opt=[] Security Options

  51. --stop-signal=SIGTERM Signal to stop a container, SIGTERM by default

  52. -t, --tty=false Allocate a pseudo-TTY

  53. -u, --user= Username or UID (format: <name|uid>[:<group|gid>])

  54. --ulimit=[] Ulimit options

  55. --uts= UTS namespace to use

  56. -v, --volume=[] Bind mount a volume

  57. --volume-driver= Optional volume driver for the container

  58. --volumes-from=[] Mount volumes from the specified container(s)

  59. -w, --workdir= Working directory inside the container

建立但不啟動一個容器.具體引數同docker run.

diff

  1. Usage: docker diff [OPTIONS] CONTAINER

  2. Inspect changes on a container's filesystem

  3. --help=false Print usage

檢視容器內發生變化的檔案。

  1. $ docker diff 87cb69be18bb

  2. A /data

  3. A /data/a.txt

  4. A /data/b

  5. A /data/backup

  6. A /data/backup/data

  7. A /data/backup/helpdocker.tgz

  8. C /root

  9. A /root/.bash_history

events

  1. Usage: docker events [OPTIONS]

  2. Get real time events from the server

  3. -f, --filter=[] Filter output based on conditions provided

  4. --help=false Print usage

  5. --since= Show all events created since timestamp

  6. --until= Stream events until this timestamp


實時輸出docker伺服器端的事件,包括容器的建立、啟動、關閉等。

  1. $ docker events

  2. 2016-08-26T10:42:08.001137030+08:00 87cb69be18bbe74ea9e14b16228ccc3347dcffb3e074fa303ca32deb46417105: (from ubuntu:14.04) die

exec

  1. Usage: docker exec [OPTIONS] CONTAINER COMMAND [ARG...]

  2. Run a command in a running container

  3. -d, --detach=false Detached mode: run command in the background

  4. --help=false Print usage

  5. -i, --interactive=false Keep STDIN open even if not attached

  6. --privileged=false Give extended privileges to the command

  7. -t, --tty=false Allocate a pseudo-TTY

  8. -u, --user= Username or UID (format: <name|uid>[:<group|gid>])

通過宿主機在正在執行的容器上執行命令。
通過宿主機在容器上建立檔案

  1. $ docker exec 87cb69be18bb touch /root/abc.txt

可通過exec命令申請一個終端,執行shell:

  1. $ docker exec -it 87cb69be18bb /bin/bash

  2. root@87cb69be18bb:/# ls

  3. abc bin boot data dev etc home ifconfig lib lib64 media mnt opt proc root run sbin srv sys tmp usr var

export

  1. Usage: docker export [OPTIONS] CONTAINER

  2. Export a container's filesystem as a tar archive

  3. --help=false Print usage

  4. -o, --output= Write to a file, instead of STDOUT

將容器的檔案系統打包成tar檔案
兩種方式:

  1. $ docker export 87cb69be18bb > web.tar

  2. $ docker export -o web.tar 87cb69be18bb

history

  1. Usage: docker history [OPTIONS] IMAGE

  2. Show the history of an image

  3. -H, --human=true Print sizes and dates in human readable format

  4. --help=false Print usage

  5. --no-trunc=false Don't truncate output

  6. -q, --quiet=false Only show numeric IDs

顯示一個映象的歷史

  1. $ docker history ubuntu:14.04

  2. IMAGE CREATED CREATED BY SIZE COMMENT

  3. d9560c05d6bd 2 weeks ago /bin/sh -c #(nop) CMD ["/bin/bash"] 0 B

  4. 001bed837092 2 weeks ago /bin/sh -c sed -i 's/^#\s*\(deb.*universe\)$/ 1.895 kB

  5. 92b3f03280cc 2 weeks ago /bin/sh -c rm -rf /var/lib/apt/lists/* 0 B

  6. 24e6f8fb4abf 2 weeks ago /bin/sh -c set -xe && echo '#!/bin/sh' > /u 194.6 kB

  7. 50ed19911a3e 2 weeks ago /bin/sh -c #(nop) ADD file:4f5a660d3f5141588d 187.8 MB

images

  1. Usage: docker images [OPTIONS] [REPOSITORY[:TAG]]

  2. List images

  3. -a, --all=false Show all images (default hides intermediate images)

  4. --digests=false Show digests

  5. -f, --filter=[] Filter output based on conditions provided

  6. --help=false Print usage

  7. --no-trunc=false Don't truncate output

  8. -q, --quiet=false Only show numeric IDs

顯示所有的映象.

import

  1. Usage: docker import [OPTIONS] file|URL|- [REPOSITORY[:TAG]]

  2. Import the contents from a tarball to create a filesystem image

  3. -c, --change=[] Apply Dockerfile instruction to the created image

  4. --help=false Print usage

  5. -m, --message= Set commit message for imported image

根據export出的tar檔案建立一個映象,和export相結合使用,這種方式容器的層結構將會丟失。

info

  1. Usage: docker info [OPTIONS]

  2. Display system-wide information

  3. --help=false Print usage

檢視docker的全域性資訊.

  1. # docker info

  2. Containers: 1

  3. Images: 25

  4. Server Version: 1.9.1

  5. Storage Driver: aufs

  6. Root Dir: /var/lib/docker/aufs

  7. Backing Filesystem: extfs

  8. Dirs: 27

  9. Dirperm1 Supported: false

  10. Execution Driver: native-0.2

  11. Logging Driver: json-file

  12. Kernel Version: 3.13.0-32-generic

  13. Operating System: Ubuntu 14.04.1 LTS

  14. CPUs: 1

  15. Total Memory: 986.8 MiB

  16. Name: ubuntu

  17. ID: ALLP:KE4W:ITY7:WUL6:QKUG:4CGB:R6IA:2UXG:227D:K6BF:EDLL:27TX

  18. WARNING: No swap limit support

inspect

  1. Usage: docker inspect [OPTIONS] CONTAINER|IMAGE [CONTAINER|IMAGE...]

  2. Return low-level information on a container or image

  3. -f, --format= Format the output using the given go template

  4. --help=false Print usage

  5. -s, --size=false Display total file sizes if the type is container

  6. --type= Return JSON for specified type, (e.g image or container)

用於檢視容器的所有配置資訊,包含容器名、環境變數、執行命令、主機配置、網路配置和資料卷配置等。

  1. $ docker inspect nextcloud

  2. [

  3. {

  4. "Id": "4f798fc8f1b5bcde38aa3702a02e06d996ae4608e8c369237754ae50e950f7ca",

  5. "Created": "2018-08-10T03:28:36.570570242Z",

  6. "Path": "/bin/bash",

  7. "Args": [],

  8. "State": {

  9. "Status": "running",

  10. "Running": true,

  11. "Paused": false,

  12. "Restarting": false,

  13. "OOMKilled": false,

  14. "Dead": false,

  15. "Pid": 19066,

  16. "ExitCode": 0,

  17. "Error": "",

  18. "StartedAt": "2018-08-15T01:51:36.80771433Z",

  19. "FinishedAt": "2018-08-15T01:51:36.267209678Z"

  20. },

  21. "Image": "sha256:c3342f6abac82e375ec5c5e64be74afee47af31e39ba480a55fd912aa45a722b",

  22. "ResolvConfPath": "/var/lib/docker/containers/4f798fc8f1b5bcde38aa3702a02e06d996ae4608e8c369237754ae50e950f7ca/resolv.conf",

  23. "HostnamePath": "/var/lib/docker/containers/4f798fc8f1b5bcde38aa3702a02e06d996ae4608e8c369237754ae50e950f7ca/hostname",

  24. "HostsPath": "/var/lib/docker/containers/4f798fc8f1b5bcde38aa3702a02e06d996ae4608e8c369237754ae50e950f7ca/hosts",

  25. "LogPath": "/var/lib/docker/containers/4f798fc8f1b5bcde38aa3702a02e06d996ae4608e8c369237754ae50e950f7ca/4f798fc8f1b5bcde38aa3702a02e06d996ae4608e8c369237754ae50e950f7ca-json.log",

  26. "Name": "/nextcloud",

  27. "RestartCount": 2,

  28. "Driver": "overlay2",

  29. "Platform": "linux",

  30. "MountLabel": "",

  31. "ProcessLabel": "",

  32. "AppArmorProfile": "docker-default",

  33. "ExecIDs": null,

kill

  1. Usage: docker kill [OPTIONS] CONTAINER [CONTAINER...]

  2. Kill a running container

  3. --help=false Print usage

  4. -s, --signal=KILL Signal to send to the container

強制終止容器.
關於stop和kill的區別:
docker stop命令給容器中的程序傳送SIGTERM訊號,預設行為是會導致容器退出,當然,容器內程式可以捕獲該訊號並自行處理,例如可以選擇忽略。而dockerkill則是給容器的程序傳送SIGKILL訊號,該訊號將會使容器必然退出。

load

  1. Usage: docker load [OPTIONS]

  2. Load an image from a tar archive or STDIN

  3. --help=false Print usage

  4. -i, --input= Read from a tar archive file, instead of STDIN

與下面的save命令相對應,將下面sava命令打包的映象通過load命令匯入。

login

  1. Usage: docker login [OPTIONS] [SERVER]

  2. Register or log in to a Docker registry.

  3. If no server is specified "https://index.docker.io/v1/" is the default.

  4. -e, --email= Email

  5. --help=false Print usage

  6. -p, --password= Password

  7. -u, --username= Username

登入到自己的Docker register,需有Docker Hub的註冊賬號,或者自行搭建的私有倉庫。

logout

  1. Usage: docker logout [OPTIONS] [SERVER]

  2. Log out from a Docker registry.

  3. If no server is specified "https://index.docker.io/v1/" is the default.

  4. --help=false Print usage

從Docker register退出登入。

logs

  1. Fetch the logs of a container

  2. -f, --follow=false Follow log output

  3. --help=false Print usage

  4. --since= Show logs since timestamp

  5. -t, --timestamps=false Show timestamps

  6. --tail=all Number of lines to show from the end of the logs

用於檢視容器的日誌,它將輸入(出)到容器標準輸入(出)的資料,作為日誌輸出到docker logs命令的終端上。常用於後臺型容器。
87cb69be18bb是一個數據流為輸入、輸出和錯誤和容器,如下命令則會列印該容器的所有互動日誌。

  1. # docker logs 87cb69be18bb

來個綜合點的,查詢容器最新的3條日誌並打上時間戳:

  1. # docker logs -f -t --tail=3 nextcloud

  2. 2018-08-15T01:51:23.500951699Z root@nextcloud:/#

  3. 2018-08-15T01:51:36.154541783Z root@nextcloud:/# exit

  4. 2018-08-15T01:51:36.154917668Z exit

network

  1. Usage: docker network [OPTIONS] COMMAND [OPTIONS]

  2. Commands:

  3. create Create a network

  4. connect Connect container to a network

  5. disconnect Disconnect container from a network

  6. inspect Display detailed network information

  7. ls List all networks

  8. rm Remove a network

建立網路

  1. Usage: docker network create [OPTIONS] NETWORK-NAME

  2. Creates a new network with a name specified by the user

  3. --aux-address=map[] auxiliary ipv4 or ipv6 addresses used by Network driver

  4. -d, --driver=bridge Driver to manage the Network

  5. --gateway=[] ipv4 or ipv6 Gateway for the master subnet

  6. --help=false Print usage

  7. --ip-range=[] allocate container ip from a sub-range

  8. --ipam-driver=default IP Address Management Driver

  9. -o, --opt=map[] set driver specific options

  10. --subnet=[] subnet in CIDR format that represents a network segment

自定義網路,可指定網段、閘道器等引數。
建立一個my_network的網路,--ip-range:指定子網段,--subnet:指定一個網段

  1. $ docker network create -d bridge --ip-range=192.168.1.0/24 --subnet=192.168.1.0/24 my_network

檢視網路

  1. Usage: docker network inspect [OPTIONS] NETWORK [NETWORK...]

  2. Displays detailed information on a network

  1. $ docker network inspect my_network

  2. [

  3. {

  4. "Name": "my_network",

  5. "Id": "414e1dd5d71ea709be885be5c283ed8080c8ca22e9baad0dc242865dd39164fd",

  6. "Scope": "local",

  7. "Driver": "bridge",

  8. "IPAM": {

  9. "Driver": "default",

  10. "Config": [

  11. {

  12. "Subnet": "192.168.1.0/24",

  13. "IPRange": "192.168.1.0/24"

  14. }

  15. ]

  16. },

  17. "Containers": {},

  18. "Options": {}

  19. }

  20. ]

列出網路

  1. Usage: docker network ls [OPTIONS]

  2. Lists networks

  3. --no-trunc=false Do not truncate the output

  4. -q, --quiet=false Only display numeric IDs

  1. $ docker network ls

  2. NETWORK ID NAME DRIVER

  3. 90b8ebd11e4f bridge bridge

  4. 77dd4f913ba1 none null

  5. 65dfd6ebddab host host

  6. 414e1dd5d71e my_network bridge

bridge為預設的網路,172.17.0.0/16網段
my_network 為自定義的網格

刪除網路

  1. Usage: docker network rm [OPTIONS] NETWORK

  2. Deletes a network

  1. $ docker network rm my_network1

連線網路

  1. Usage: docker network connect [OPTIONS] NETWORK CONTAINER

  2. Connects a container to a network

將容器連線到指定的網路

1.建立一個容器,不指定網路,預設會用bridge網路。

  1. $ #docker run -it --name=web ubuntu:14.04 /bin/bash

會看到預設有eth0:172.17.0.0/16段

  1. root@d35ef0bda3fb:/# ifconfig

  2. eth0 Link encap:Ethernet HWaddr 02:42:ac:11:00:02

  3. inet addr:172.17.0.2 Bcast:0.0.0.0 Mask:255.255.0.0

  4. inet6 addr: fe80::42:acff:fe11:2/64 Scope:Link

  5. UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1

  6. RX packets:5 errors:0 dropped:0 overruns:0 frame:0

  7. TX packets:6 errors:0 dropped:0 overruns:0 carrier:0

  8. collisions:0 txqueuelen:0

  9. RX bytes:418 (418.0 B) TX bytes:508 (508.0 B)

2.將該容器連線到my_network網路
連線到的容器必須是running狀態。

  1. $ docker network connect my_network web

3.檢視容器網路狀態
會看到多出一個eth1:192.168.1.0/24網段

  1. root@d35ef0bda3fb:/# ifconfig

  2. eth0 Link encap:Ethernet HWaddr 02:42:ac:11:00:02

  3. inet addr:172.17.0.2 Bcast:0.0.0.0 Mask:255.255.0.0

  4. inet6 addr: fe80::42:acff:fe11:2/64 Scope:Link

  5. UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1

  6. RX packets:8 errors:0 dropped:0 overruns:0 frame:0

  7. TX packets:8 errors:0 dropped:0 overruns:0 carrier:0

  8. collisions:0 txqueuelen:0

  9. RX bytes:648 (648.0 B) TX bytes:648 (648.0 B)

  10. eth1 Link encap:Ethernet HWaddr 02:42:c0:a8:01:02

  11. inet addr:192.168.1.2 Bcast:0.0.0.0 Mask:255.255.255.0

  12. inet6 addr: fe80::42:c0ff:fea8:102/64 Scope:Link

  13. UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1

  14. RX packets:8 errors:0 dropped:0 overruns:0 frame:0

  15. TX packets:8 errors:0 dropped:0 overruns:0 carrier:0

  16. collisions:0 txqueuelen:0

  17. RX bytes:648 (648.0 B) TX bytes:648 (648.0 B)

斷開網路

  1. Usage: docker network disconnect [OPTIONS] NETWORK CONTAINER

  2. Disconnects container from a network

將容器與一個網路斷開

  1. # docker network disconnect my_network web

斷開後該容器不在擁有該網路的地址。

pause

  1. Usage: docker pause [OPTIONS] CONTAINER [CONTAINER...]

  2. Pause all processes within a container

  3. --help=false Print usage

暫停容器內的所有程序。
此時,通過docker stats可以觀察到此時的資源使用情況是固定不變的,通過docker logs -f也觀察不到日誌的進一步輸出。

  1. $ docker pause 87cb69be18bb

容器的狀態變為:Up About an hour (Paused)
docker unpause 重新啟動一個容器。

port

  1. Usage: docker port [OPTIONS] CONTAINER [PRIVATE_PORT[/PROTO]]

  2. List port mappings or a specific mapping for the CONTAINER

輸出容器埠與宿主機埠的對映情況

  1. # docker port blog

  2. 80/tcp -> 0.0.0.0:80

容器blog的內部埠80對映到宿主機的80埠,這樣可通過宿主機的80埠檢視容器blog提供的服務

ps

  1. Usage: docker ps [OPTIONS]

  2. List containers

  3. -a, --all=false Show all containers (default shows just running)

  4. --before= Show only container created before Id or Name

  5. -f, --filter=[] Filter output based on conditions provided

  6. --format= Pretty-print containers using a Go template

  7. --help=false Print usage

  8. -l, --latest=false Show the latest created container, include non-running

  9. -n=-1 Show n last created containers, include non-running

  10. --no-trunc=false Don't truncate output

  11. -q, --quiet=false Only display numeric IDs

  12. -s, --size=false Display total file sizes

  13. --since= Show created since Id or Name, include non-running


列出所有容器,其中docker ps用於檢視正在執行的容器,ps -a則用於檢視所有容器。

pull

  1. Usage: docker pull [OPTIONS] NAME[:TAG|@DIGEST]

  2. Pull an image or a repository from a registry

  3. -a, --all-tags=false Download all tagged images in the repository

  4. --disable-content-trust=true Skip image verification

  5. --help=false Print usage

從registry中拉取映象。

push

  1. Usage: docker push [OPTIONS] NAME[:TAG]

  2. Push an image or a repository to a registry

  3. --disable-content-trust=true Skip image signing

  4. --help=false Print usage


本地的映象上傳到registry中

rename

  1. Usage: docker rename [OPTIONS] OLD_NAME NEW_NAME

  2. Rename a container

  3. --help=false Print usage


更改容器的名字.
將容器tender_lichterman更名為web1.

  1. # docker rename tender_lichterman web1

restart

  1. Usage: docker restart [OPTIONS] CONTAINER [CONTAINER...]

  2. Restart a container

  3. --help=false Print usage

  4. -t, --time=10 Seconds to wait for stop before killing the container

重啟一個容器。

rm

  1. Usage: docker rm [OPTIONS] CONTAINER [CONTAINER...]

  2. Remove one or more containers

  3. -f, --force=false Force the removal of a running container (uses SIGKILL)

  4. --help=false Print usage

  5. -l, --link=false Remove the specified link

  6. -v, --volumes=false Remove the volumes associated with the container

刪除容器。
不可以刪除一個執行中的容器,必須先用docker stop或docker kill使其停止。
當然可以強制刪除,必須加-f引數。
如果要一次性刪除所有容器,可使用 docker rm -f $(docker ps -a -q),其中,-q指的是隻列出容器的ID。

rmi

  1. Usage: docker rmi [OPTIONS] IMAGE [IMAGE...]

  2. Remove one or more images

  3. -f, --force=false Force removal of the image

  4. --help=false Print usage

  5. --no-prune=false Do not delete untagged parents

刪除一個或多個映象。

save

  1. Usage: docker save [OPTIONS] IMAGE [IMAGE...]

  2. Save an image(s) to a tar archive (streamed to STDOUT by default)

  3. --help=false Print usage

  4. -o, --output= Write to a file, instead of STDOUT

將映象打包,與上面的load命令相對應.
兩種方式:

  1. # docker save webserver >webserver.tar

  2. # docker save -o webserver.tar webserver:v1

search

  1. Usage: docker search [OPTIONS] TERM

  2. Search the Docker Hub for images

  3. --automated=false Only show automated builds

  4. --help=false Print usage

  5. --no-trunc=false Don't truncate output

  6. -s, --stars=0 Only displays with at least x stars

查詢映象。

start

  1. Usage: docker start [OPTIONS] CONTAINER [CONTAINER...]

  2. Start one or more stopped containers

  3. -a, --attach=false Attach STDOUT/STDERR and forward signals

  4. --help=false Print usage

  5. -i, --interactive=false Attach container's STDIN

啟動一個或多個停止的映象。
啟動一個映象並啟動一個互動試的終端。

  1. $ docker start -ia 87cb69be18bb

  2. root@87cb69be18bb:/# ls

stats

  1. Usage: docker stats [OPTIONS] CONTAINER [CONTAINER...]

  2. Display a live stream of container(s) resource usage statistics

  3. --help=false Print usage

  4. --no-stream=false Disable streaming stats and only pull the first result

動態顯示容器的資源消耗情況,包括:CPU、記憶體、網路I/O.

stop

  1. Usage: docker stop [OPTIONS] CONTAINER [CONTAINER...]

  2. Stop a running container.

  3. Sending SIGTERM and then SIGKILL after a grace period

  4. --help=false Print usage

  5. -t, --time=10 Seconds to wait for stop before killing it

停止一個正在執行的容器。

tag

  1. Usage: docker tag [OPTIONS] IMAGE[:TAG] [REGISTRYHOST/][USERNAME/]NAME[:TAG]

  2. Tag an image into a repository

  3. -f, --force=false Force

  4. --help=false Print usage

對repository中的映象進行重新命名。tag後的映象和原映象擁有相同的ID。

top

  1. Usage: docker top [OPTIONS] CONTAINER [ps OPTIONS]

  2. Display the running processes of a container

檢視容器中正在執行的程序。

  1. $ docker top 87cb69be18bb

  2. UID PID PPID C STIME TTY TIME CMD

  3. root 512 679 0 12:59 pts/3 00:00:00 /bin/bash

unpause

  1. Usage: docker unpause [OPTIONS] CONTAINER [CONTAINER...]

  2. Unpause all processes within a container

  3. --help=false Print usage

恢復容器內暫停的程序,與pause引數相對應。

version

  1. Usage: docker version [OPTIONS]

  2. Show the Docker version information

  3. -f, --format= Format the output using the given go template

  4. --help=false Print usage

檢視docker版本資訊

  1. $ docker version

  2. Client:

  3. Version: 1.9.1

  4. API version: 1.21

  5. Go version: go1.4.3

  6. Git commit: a34a1d5

  7. Built: Fri Nov 20 17:56:04 UTC 2015

  8. OS/Arch: linux/amd64

  9. Server:

  10. Version: 1.9.1

  11. API version: 1.21

  12. Go version: go1.4.3

  13. Git commit: a34a1d5

  14. Built: Fri Nov 20 17:56:04 UTC 2015

  15. OS/Arch: linux/amd64

volume

  1. Usage: docker volume [OPTIONS] [COMMAND]

  2. Manage Docker volumes

  3. Commands:

  4. create Create a volume

  5. inspect Return low-level information on a volume

  6. ls List volumes

  7. rm Remove a volume

管理docker資料卷.

建立資料卷

  1. Usage: docker volume create [OPTIONS]

  2. Create a volume

  3. -d, --driver=local Specify volume driver name

  4. --name= Specify volume name

  5. -o, --opt=map[] Set driver specific options

1.建立一個名為data_v的資料卷

  1. $ docker volume create --name='data_v'

2.建立完資料卷後,其他容器即可掛載該容器。可用於資料共享。
3.建立一個容器,把名為data_v的資料卷掛載到容器的/data目錄

  1. $ docker run -it -v data_v:/data ubuntu:14.04 /bin/bash

檢視資料卷

  1. Usage: docker volume inspect [OPTIONS] VOLUME [VOLUME...]

  2. Return low-level information on a volume

  3. -f, --format= Format the output using the given go template

檢視剛剛建立的資料卷

  1. $ docker volume inspect data_v

  2. [

  3. {

  4. "Name": "data_v",

  5. "Driver": "local",

  6. "Mountpoint": "/var/lib/docker/volumes/data_v/_data"

  7. }

  8. ]

列出資料卷

  1. Usage: docker volume ls [OPTIONS]

  2. List volumes

  3. -f, --filter=[] Provide filter values (i.e. 'dangling=true')

  4. -q, --quiet=false Only display volume names

  1. $ docker volume ls

  2. DRIVER VOLUME NAME

  3. local 04ad14c9c5dbeecd08fe37927024b73efc809da9698eb7000c63e214e929ec15

  4. local 067591aee8ac7ab721de3cba6896c9574703d434604e74f97ff489eecda42777

  5. local 127dcc895206f024f9ece5d88da97db7ea0a9b689f2cf662a38f9baaba441755

  6. local 19fc4d60583be9cda8b0d3f408e64c69efcad90dcab617655b22983588cc8a7c

  7. local 1a1020d07eddf1d796dcef60e89f4a65cfd440c4817ea5d2d9cc608af8b3c139

刪除資料卷

  1. Usage: docker volume rm [OPTIONS] VOLUME [VOLUME...]

  1. $ docker volume rm data_v

wait

  1. Usage: docker wait [OPTIONS] CONTAINER [CONTAINER...]

  2. Block until a container stops, then print its exit code

  3. --help=false Print usage

捉容器停止時的退出碼。
執行此命令後,該命令會“hang”在當前終端,直到容器停止,此時,會打印出容器的退出碼。

未完待續......