docker [OPTIONS] command
Usage: docker [OPTIONS] COMMAND [arg...]
docker daemon [ --help | ... ]
docker [ -h | --help | -v | --version ]
A self-sufficient runtime for containers.
Options:
--config=~/.docker Location of client config files
-D,--debug=false Enable debug mode
-H,--host=[] Daemonsocket(s) to connect to
-h,--help=false Print usage
-l,--log-level=info Set the logginglevel
--tls=false Use TLS; implied by--tlsverify
--tlscacert=~/.docker/ca.pem Trust certs signed only by this CA
--tlscert=~/.docker/cert.pem Path to TLS certificate file
--tlskey=~/.docker/key.pem Path to TLS key file
--tlsverify=false Use TLS and verify the remote
-v, --version=false Print version information and quit
network
Usage: docker network [OPTIONS] COMMAND [OPTIONS] Commands: create Create a network connect Connect container to a network disconnect Disconnect container from a network inspect Display detailed network information ls List all networks rm Remove a network |
創建網絡
Usage: docker network create [OPTIONS] NETWORK-NAME Creates a new network with a name specified by the user --aux-address=map[] auxiliary ipv4 or ipv6 addresses used by Network driver -d, --driver=bridge Driver to manage the Network --gateway=[] ipv4 or ipv6 Gateway for the master subnet --help=false Print usage --ip-range=[] allocate container ip from a sub-range --ipam-driver=default IP Address Management Driver -o, --opt=map[] set driver specific options --subnet=[] subnet in CIDR format that represents a network segment |
自定義網絡,可指定網段、網關等參數。
創建一個my_network的網絡,--ip-range:指定子網段,--subnet:指定一個網段
# docker network create -d bridge--ip-range=192.168.1.0/24 --subnet=192.168.1.0/24 my_network
查看網絡
Usage: docker network inspect [OPTIONS] NETWORK [NETWORK...] Displays detailed information on a network |
# docker network inspect my_network
[ { "Name": "my_network", "Id": "414e1dd5d71ea709be885be5c283ed8080c8ca22e9baad0dc242865dd39164fd", "Scope": "local", "Driver": "bridge", "IPAM": { "Driver": "default", "Config": [ { "Subnet": "192.168.1.0/24", "IPRange": "192.168.1.0/24" } ] }, "Containers": {}, "Options": {} } ] |
列出網絡
Usage: docker network ls [OPTIONS] Lists networks --no-trunc=false Do not truncate the output -q, --quiet=false Only display numeric IDs |
# docker network ls
NETWORK ID NAME DRIVER 90b8ebd11e4f bridge bridge 77dd4f913ba1 none null 65dfd6ebddab host host 414e1dd5d71e my_network bridge |
bridge爲默認的網絡,172.17.0.0/16網段
my_network 爲自定義的網格
刪除網絡
Usage: docker network rm [OPTIONS] NETWORK Deletes a network |
# docker network rm my_network1
連接網絡
Usage: docker network connect [OPTIONS] NETWORK CONTAINER Connects a container to a network |
將指定的網絡連接到容器。
創建一個容器,不指定網絡,默認會用bridge網絡。
#docker run -it --name=web ubuntu:14.04/bin/bash
會看到默認有eth0:172.17.0.0/16段
root@d35ef0bda3fb:/# ifconfig eth0 Link encap:Ethernet HWaddr 02:42:ac:11:00:02 inet addr:172.17.0.2 Bcast:0.0.0.0 Mask:255.255.0.0 inet6 addr: fe80::42:acff:fe11:2/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:5 errors:0 dropped:0 overruns:0 frame:0 TX packets:6 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:418 (418.0 B) TX bytes:508 (508.0 B) lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: ::1/128 Scope:Host UP LOOPBACK RUNNING MTU:65536 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:0 (0.0 B) TX bytes:0 (0.0 B) |
2. 將該容器連接到my_network網絡
連接到的容器必須是running狀態。
# docker network connect my_network web
3. 查看容器網絡狀態
會看到多出一個eth1:192.168.1.0/24網段
root@d35ef0bda3fb:/# ifconfig eth0 Link encap:Ethernet HWaddr 02:42:ac:11:00:02 inet addr:172.17.0.2 Bcast:0.0.0.0 Mask:255.255.0.0 inet6 addr: fe80::42:acff:fe11:2/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:8 errors:0 dropped:0 overruns:0 frame:0 TX packets:8 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:648 (648.0 B) TX bytes:648 (648.0 B) eth1 Link encap:Ethernet HWaddr 02:42:c0:a8:01:02 inet addr:192.168.1.2 Bcast:0.0.0.0 Mask:255.255.255.0 inet6 addr: fe80::42:c0ff:fea8:102/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:8 errors:0 dropped:0 overruns:0 frame:0 TX packets:8 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:648 (648.0 B) TX bytes:648 (648.0 B) lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: ::1/128 Scope:Host UP LOOPBACK RUNNING MTU:65536 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:0 (0.0 B) TX bytes:0 (0.0 B) |
斷開網絡
Usage: docker network disconnect [OPTIONS] NETWORK CONTAINER Disconnects container from a network |
將容器與一個網絡斷開
# docker network disconnect my_network web
斷開後該容器不在擁有該網絡的地址。
pause
Usage: docker pause [OPTIONS] CONTAINER [CONTAINER...] Pause all processes within a container --help=false Print usage |
暫停容器內的所有進程。
此時,通過docker stats可以觀察到此時的資源使用情況是固定不變的,通過docker logs -f也觀察不到日誌的進一步輸出。
# docker pause 87cb69be18bb
容器的狀態變爲:Up About an hour (Paused)
docker unpause 重新啓動一個容器。
port
Usage: docker port [OPTIONS] CONTAINER [PRIVATE_PORT[/PROTO]] List port mappings or a specific mapping for the CONTAINER |
輸出容器端口與宿主機端口的映射情況
# docker port blog
80/tcp -> 0.0.0.0:80
容器blog的內部端口80映射到宿主機的80端口,這樣可通過宿主機的80端口查看容器blog提供的服務
ps
Usage: docker ps [OPTIONS] List containers -a, --all=false Show all containers (default shows just running) --before= Show only container created before Id or Name -f, --filter=[] Filter output based on conditions provided --format= Pretty-print containers using a Go template --help=false Print usage -l, --latest=false Show the latest created container, include non-running -n=-1 Show n last created containers, include non-running --no-trunc=false Don't truncate output -q, --quiet=false Only display numeric IDs -s, --size=false Display total file sizes --since= Show created since Id or Name, include non-running |
列出所有容器,其中docker ps用於查看正在運行的容器,ps -a則用於查看所有容器。
pull
Usage: docker pull [OPTIONS] NAME[:TAG|@DIGEST] Pull an image or a repository from a registry -a, --all-tags=false Download all tagged images in the repository --disable-content-trust=true Skip image verification --help=false Print usage |
從registry中拉取鏡像。
push
Usage: docker push [OPTIONS] NAME[:TAG] Push an image or a repository to a registry --disable-content-trust=true Skip image signing --help=false Print usage |
本地的鏡像上傳到registry中
rename
Usage: docker rename [OPTIONS] OLD_NAME NEW_NAME Rename a container --help=false Print usage |
更改容器的名字。
將容器tender_lichterman更名爲web1.
# docker rename tender_lichterman web1
restart
Usage: docker restart [OPTIONS] CONTAINER [CONTAINER...] Restart a container --help=false Print usage -t, --time=10 Seconds to wait for stop before killing the container |
重啓一個容器。
rm
Usage: docker rm [OPTIONS] CONTAINER [CONTAINER...] Remove one or more containers -f, --force=false Force the removal of a running container (uses SIGKILL) --help=false Print usage -l, --link=false Remove the specified link -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
Usage: docker rmi [OPTIONS] IMAGE [IMAGE...] Remove one or more images -f, --force=false Force removal of the image --help=false Print usage --no-prune=false Do not delete untagged parents |
刪除一個或多個鏡像。
save
Usage: docker save [OPTIONS] IMAGE [IMAGE...] Save an image(s) to a tar archive (streamed to STDOUT by default) --help=false Print usage -o, --output= Write to a file, instead of STDOUT |
將鏡像打包,與上面的load命令相對應.
兩種方式:
# docker save webserver >webserver.tar
# docker save -o webserver.tar webserver:v1
search
Usage: docker search [OPTIONS] TERM Search the Docker Hub for images --automated=false Only show automated builds --help=false Print usage --no-trunc=false Don't truncate output -s, --stars=0 Only displays with at least x stars |
查找鏡像。
start
Usage: docker start [OPTIONS] CONTAINER [CONTAINER...] Start one or more stopped containers -a, --attach=false Attach STDOUT/STDERR and forward signals --help=false Print usage -i, --interactive=false Attach container's STDIN |
啓動一個或多個停止的鏡像。
啓動一個鏡像並啓動一個交互試的終端。
# docker start -ia 87cb69be18bb
root@87cb69be18bb:/# ls
stats
Usage: docker stats [OPTIONS] CONTAINER [CONTAINER...] Display a live stream of container(s) resource usage statistics --help=false Print usage --no-stream=false Disable streaming stats and only pull the first result |
動態顯示容器的資源消耗情況,包括:CPU、內存、網絡I/O.
stop
Usage: docker stop [OPTIONS] CONTAINER [CONTAINER...] Stop a running container. Sending SIGTERM and then SIGKILL after a grace period --help=false Print usage -t, --time=10 Seconds to wait for stop before killing it |
停止一個正在運行的容器。
tag
Usage: docker tag [OPTIONS] IMAGE[:TAG] [REGISTRYHOST/][USERNAME/]NAME[:TAG] Tag an image into a repository -f, --force=false Force --help=false Print usage |
對repository中的鏡像進行重命名。
top
Usage: docker top [OPTIONS] CONTAINER [ps OPTIONS] Display the running processes of a container |
查看容器中正在運行的進程。
# docker top 87cb69be18bb UID PID PPID C STIME TTY TIME CMD root 512 679 0 12:59 pts/3 00:00:00 /bin/bash |
unpause
Usage: docker unpause [OPTIONS] CONTAINER [CONTAINER...] Unpause all processes within a container --help=false Print usage |
恢復容器內暫停的進程,與pause參數相對應。
version
Usage: docker version [OPTIONS] Show the Docker version information -f, --format= Format the output using the given go template --help=false Print usage |
查看docker版本信息
# docker version Client: Version: 1.9.1 API version: 1.21 Go version: go1.4.3 Git commit: a34a1d5 Built: Fri Nov 20 17:56:04 UTC 2015 OS/Arch: linux/amd64 Server: Version: 1.9.1 API version: 1.21 Go version: go1.4.3 Git commit: a34a1d5 Built: Fri Nov 20 17:56:04 UTC 2015 OS/Arch: linux/amd64 |
volume
Usage: docker volume [OPTIONS] [COMMAND] Manage Docker volumes Commands: create Create a volume inspect Return low-level information on a volume ls List volumes rm Remove a volume |
管理docker數據卷.
創建數據卷
Usage: docker volume create [OPTIONS] Create a volume -d, --driver=local Specify volume driver name --name= Specify volume name -o, --opt=map[] Set driver specific options |
1. 創建一個名爲data_v的數據卷
# docker volume create --name='data_v'
2. 創建完數據卷後,其他容器即可掛載該容器。可用於數據共享。
3. 創建一個容器,把名爲data_v的數據卷掛載到容器的/data目錄
# docker run -it -v data_v:/data ubuntu:14.04 /bin/bash
查看數據卷
Usage: docker volume inspect [OPTIONS] VOLUME [VOLUME...] Return low-level information on a volume -f, --format= Format the output using the given go template |
查看剛剛創建的數據卷
# docker volume inspect data_v
[ { "Name": "data_v", "Driver": "local", "Mountpoint": "/var/lib/docker/volumes/data_v/_data" } ] |
列出數據卷
Usage: docker volume ls [OPTIONS] List volumes -f, --filter=[] Provide filter values (i.e. 'dangling=true') -q, --quiet=false Only display volume names |
# docker volume ls
刪除數據卷
Usage: docker volume rm [OPTIONS] VOLUME [VOLUME...] |
# docker volume rm data_v
wait
Usage: docker wait [OPTIONS] CONTAINER [CONTAINER...] Block until a container stops, then print its exit code --help=false Print usage |
捉容器停止時的退出碼。
執行此命令後,該命令會“hang”在當前終端,直到容器停止,此時,會打印出容器的退出碼。