Usage: docker daemon [OPTIONS] A self-sufficient runtime for linux containers. Options: --api-cors-header="" Set CORS headers in the remote API -b, --bridge="" Attach containers to a network bridge --bip="" Specify network bridge IP -D, --debug=false Enable debug mode --default-gateway="" Container default gateway IPv4 address --default-gateway-v6="" Container default gateway IPv6 address --dns=[] DNS server to use --dns-search=[] DNS search domains to use --default-ulimit=[] Set default ulimit settings for containers -e, --exec-driver="native" Exec driver to use --exec-opt=[] Set exec driver options --exec-root="/var/run/docker" Root of the Docker execdriver --fixed-cidr="" IPv4 subnet for fixed IPs --fixed-cidr-v6="" IPv6 subnet for fixed IPs -G, --group="docker" Group for the unix socket -g, --graph="/var/lib/docker" Root of the Docker runtime -H, --host=[] Daemon socket(s) to connect to -h, --help=false Print usage --icc=true Enable inter-container communication --insecure-registry=[] Enable insecure registry communication --ip=0.0.0.0 Default IP when binding container ports --ip-forward=true Enable net.ipv4.ip_forward --ip-masq=true Enable IP masquerading --iptables=true Enable addition of iptables rules --ipv6=false Enable IPv6 networking -l, --log-level="info" Set the logging level --label=[] Set key=value labels to the daemon --log-driver="json-file" Default driver for container logs --log-opt=[] Log driver specific options --mtu=0 Set the containers network MTU -p, --pidfile="/var/run/docker.pid" Path to use for daemon PID file --registry-mirror=[] Preferred Docker registry mirror -s, --storage-driver="" Storage driver to use --selinux-enabled=false Enable selinux support --storage-opt=[] Set storage driver options --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 --userland-proxy=true Use userland proxy for loopback traffic
devicemapper使用自动精简配置以及Copy on Write(COW)快照。对于每一个graph位置通常是在/var/lib/docker/devicemapper中,通常被分为两块设备,一块给数据,一块给metadata。默认的,这些块设备是通过使用自动创建的零散文件回送挂载来自动创建的。Refer to Storage driver options below for a way how to customize this setup.~jpetazzo/Resizing Docker containers with the Device Mapper plugin article explains how to tune your existing setup without the use of options.
-f, --file="" Name of the Dockerfile (Default is 'PATH/Dockerfile') --force-rm=false Always remove intermediate containers --no-cache=false Do not use cache when building the image --pull=false Always attempt to pull a newer version of the image -q, --quiet=false Suppress the verbose output generated by the containers --rm=true Remove intermediate containers after a successful build -t, --tag="" Repository name (and optionally a tag) for the image -m, --memory="" Memory limit for all build containers --memory-swap="" Total memory (memory + swap), `-1` to disable swap -c, --cpu-shares CPU Shares (relative weight) --cpuset-mems="" MEMs in which to allow execution, e.g. `0-3`, `0,1` --cpuset-cpus="" CPUs in which to allow execution, e.g. `0-3`, `0,1` --cgroup-parent="" Optional parent cgroup for the container --ulimit=[] Ulimit options
-a, --author= Author (e.g., "John Hannibal Smith <[email protected]>") -c, --change=[] Apply Dockerfile instruction to the created image --help=false Print usage -m, --message= Commit message -p, --pause=true Pause container during commit
例子
$ sudo docker ps ID IMAGE COMMAND CREATED STATUS PORTS c3f279d17e0a ubuntu:12.04 /bin/bash 7 days ago Up 25 hours 197387f1b436 ubuntu:12.04 /bin/bash 7 days ago Up 25 hours $ sudo docker commit c3f279d17e0a SvenDowideit/testimage:version3 f5283438590d $ sudo docker images | head REPOSITORY TAG ID CREATED VIRTUAL SIZE SvenDowideit/testimage version3 f5283438590d 16 seconds ago 335.7 M
提交一个重新配置过的容器到镜像
$ sudo docker ps ID IMAGE COMMAND CREATED STATUS PORTS c3f279d17e0a ubuntu:12.04 /bin/bash 7 days ago Up 25 hours 197387f1b436 ubuntu:12.04 /bin/bash 7 days ago Up 25 hours $ sudo docker inspect -f "{{ .Config.Env }}" c3f279d17e0a [HOME=/ PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin] $ sudo docker commit --change "ENV DEBUG true" c3f279d17e0a SvenDowideit/testimage:version3 f5283438590d $ sudo docker inspect -f "{{ .Config.Env }}" f5283438590d [HOME=/ PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin DEBUG=true]
$ sudo docker diff b448f729a0b0 C /run A /run/secrets
总结
diff会列出3种容器内文件状态变化(A - Add, D - Delete, C - Change )的列表清单。构建Image的过程中需要的调试指令。
7.7 events 参数
用法
Usage: docker events [OPTIONS]
Get real time events from the server
-f, --filter=[] Filter output based on conditions provided --help=false Print usage --since= Show all events created since timestamp --until= Stream events until this timestamp
-H, --human=true Print sizes and dates in human readable format --help=false Print usage --no-trunc=false Don't truncate output -q, --quiet=false Only show numeric IDs
例子
$ sudo docker history postgres IMAGE CREATED CREATED BY SIZE COMMENT 730d1d72bda2 4 weeks ago /bin/sh -c #(nop) CMD ["postgres"] 0 B 3e840dbb5474 4 weeks ago /bin/sh -c #(nop) EXPOSE 5432/tcp 0 B 4df8a54cf33a 4 weeks ago /bin/sh -c #(nop) ENTRYPOINT &{["/docker-entr 0 B 09e02a9f8afe 4 weeks ago /bin/sh -c #(nop) COPY file:090d83d34addb45c3 2.761 kB 39172f8b90f2 4 weeks ago /bin/sh -c #(nop) VOLUME [/var/lib/postgresql 0 B 3fa84fbfdec9 4 weeks ago /bin/sh -c #(nop) ENV PGDATA=/var/lib/postgre 0 B c5d75e7f9094 4 weeks ago /bin/sh -c #(nop) ENV PATH=/usr/lib/postgresq 0 B a95070c23e86 4 weeks ago /bin/sh -c mkdir -p /var/run/postgresql && ch 0 B 64957633c267 4 weeks ago /bin/sh -c apt-get update && apt-get install 116.4 MB a814508841fa 4 weeks ago /bin/sh -c echo 'deb http://apt.postgresql.or 66 B 49915906faae 4 weeks ago /bin/sh -c #(nop) ENV PG_VERSION=9.4.4-1.pgdg 0 B b41b53da5fba 4 weeks ago /bin/sh -c #(nop) ENV PG_MAJOR=9.4 0 B 02fa71f1fa38 4 weeks ago /bin/sh -c apt-key adv --keyserver ha.pool.sk 3.212 kB 0b82f508e063 4 weeks ago /bin/sh -c mkdir /docker-entrypoint-initdb.d 0 B e07b5a739ed9 4 weeks ago /bin/sh -c #(nop) ENV LANG=en_US.utf8 0 B c783ebe7a1d4 4 weeks ago /bin/sh -c apt-get update && apt-get install 19.54 MB 8b6b2a3b7f9c 4 weeks ago /bin/sh -c apt-get update && apt-get install 3.758 MB 22ed955cce18 5 weeks ago /bin/sh -c gpg --keyserver pool.sks-keyserver 98.87 kB 26a84c436db4 5 weeks ago /bin/sh -c groupadd -r postgres && useradd -r 330.4 kB 9a61b6b1315e 5 weeks ago /bin/sh -c #(nop) CMD ["/bin/bash"] 0 B 902b87aaaec9 5 weeks ago /bin/sh -c #(nop) ADD file:e1dd18493a216ecd0c 125.2 MB
总结
打印指定Image中每一层Image命令行的历史记录。
7.11 images 参数
使用方法
docker images [OPTIONS] [REPOSITORY]
List images
-a, --all=false Show all images (default hides intermediate images) --digests=false Show digests -f, --filter=[] Filter output based on conditions provided --help=false Print usage --no-trunc=false Don't truncate output -q, --quiet=false Only show numeric IDs
例子:
查询本里存储的镜像
$ sudo docker imgaes REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE docker.io/ubuntu latest 63e3c10217b8 7 days ago 188.3 MB docker.google/etcd 2.1.1 2c319269dd15 8 days ago 23.32 MB docker.io/postgres latest 730d1d72bda2 2 weeks ago 265.3 MB centos latest 770327a1e9e7 2 weeks ago 418.9 MB …
将ID完整展现
$ sudo docker images --no-trunc REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE scratch1 latest dc869bfd3085af05a1a070c7409193e8be88de00ff4560e2e9af80ffa9d2041d 58 minutes ago 0 B registry.liugang/centos latest 770327a1e9e746cf8d4449a7134e87917982b33c7f5cea584d941350f5ead7ac 4 weeks ago 418.9 MB registry.liugang/busybox latest 8c2e06607696bd4afb3d03b687e361cc43cf8ec1a4a725bc96e39f05ba97dd55 4 months ago 2.43 MB docker.io/scratch latest 511136ea3c5a64f264b78b5433614aec563103b4d4702f3ba7d4d2698e22c158 2 years ago 0 B
使用该命令将展现没有tag的镜像
$ sudo docker images --filter "dangling=true" REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE <none> <none> b133995b6291 About an hour ago 0 B <none> <none> 6fae83243a01 About an hour ago 0 B <none> <none> 4c6412305cfa About an hour ago 0 B
总结
其中第一字段是image镜像的名称;TAG一般表示为版本号,也可以自己定义 ;IMAGE ID 表示镜像的唯一ID ,这也是判断两个镜像文件是否为同一个的判断标准。
7.12 info 参数
用法
Usage: docker info [OPTIONS]
Display system-wide information
--help=false Print usage
例子
$ sudo docker -D info Containers: 6 Images: 30 Storage Driver: devicemapper Pool Name: docker-8:3-28326-pool Pool Blocksize: 65.54 kB Backing Filesystem: xfs Data file: /dev/loop0 Metadata file: /dev/loop1 Data Space Used: 1.37 GB Data Space Total: 107.4 GB Data Space Available: 44.49 GB Metadata Space Used: 2.245 MB Metadata Space Total: 2.147 GB Metadata Space Available: 2.145 GB Udev Sync Supported: true Deferred Removal Enabled: false Data loop file: /var/lib/docker/devicemapper/devicemapper/data Metadata loop file: /var/lib/docker/devicemapper/devicemapper/metadata Library Version: 1.02.93-RHEL7 (2015-01-28) Execution Driver: native-0.2 Logging Driver: json-file Kernel Version: 3.10.0-229.el7.x86_64 Operating System: CentOS Linux 7 (Core) CPUs: 1 Total Memory: 979.7 MiB Name: localhost.localdomain ID: PRVB:3SDE:YL4E:JT5P:5BIR:BUC5:PHXI:HG4B:P753:Y2BI:U7OU:YPGC
Log out from a Docker registry, if no server is specified "https://index.docker.io/v1/" is the default.
--help=false Print usage
例子
$ sudo docker logout localhost:8080
7.16 logs 参数
用法
Usage: docker logs [OPTIONS] CONTAINER
Fetch the logs of a container
-f, --follow=false Follow log output --help=false Print usage --since= Show logs since timestamp -t, --timestamps=false Show timestamps --tail=all Number of lines to show from the end of the logs
如果不指定 –driver 参数,该命令将自动为你创建一个bridge类型的网络。该网络对应与传统的docker0网桥。当使用 docker run 启动一个容器时,它将自动连接到这个bridge网络。你不能删除这个默认的网络但是可以使用docker network create 命令创建一个新的:
docker network create -d bridge my-bridge-network
birdge网络是单docker引擎的隔离网络(Bridge networks are isolated networks on a single Engine installation)。如果你想创建一个跨越多个docker主机引擎的网络,你必须创建一个overlay类型的网络。与birdge网络不同,overlay网络创建需要提前准备一些配置:
当创建一个网络时,docker Engine 会默认为该网络创建一个非重叠子网。这个子网并不是已存在子网的划分,它纯粹为了IP寻址(It is purely for ip-addressing purposes)。你可以覆盖这个默认的,然后使用 –subnet 选项来特别定义。在bridge网络上你可以这样定义:
sudo docker network ls NETWORK ID NAME DRIVER 7fca4eb8c647 bridge bridge 9f904ee27bf5 none null cf03ee007fb4 host host 78b03ee04fc4 multi-host overlay
使用 –no-trunc 选项来显示整个网络的ID
docker network ls --no-trunc NETWORK ID NAME DRIVER 18a2866682b85619a026c81b98a5e375bd33e1b0936a26cc497c283d27bae9b3 none null c288470c46f6c8949c5f7e5099b5b7947b07eabe8d9a27d79a9cbf111adcbf47 host host 7b369448dccbf865d397c8d2be0cda7cf7edc6b0945f77d2529912ae917a0185 bridge bridge 95e74588f40db048e86320c6526440c504650a1ff3e9f7d60a497c4d2163e5bd foo bridge
network rm
删除一个网络,在删除该网络之前,必须断开与该网络连接的任何容器。
docker network rm my-network
7.18 search 参数
说明:搜索镜像仓库
用法
Usage: docker search [OPTIONS] TERM
Search the Docker Hub for images
--automated=false Only show automated builds --help=false Print usage --no-index=false Don't prepend index to output --no-trunc=false Don't truncate output -s, --stars=0 Only displays with at least x stars
例子
$ sudo docker search ubuntu
从官方仓库中搜索出含有关键字ubuntu的镜像:
INDEX NAM DESCRIPTION STARS OFFICIAL AUTOMATED docker.io docker.io/ubuntu Ubuntu is a Debian-based Linux operating s... 2046 [OK] docker.io docker.io/ubuntu-upstart Upstart is an event-based replacement for ... 30 [OK] docker.io docker.io/torusware/speedus-ubuntu Always updated official Ubuntu docker imag... 25 [OK] docker.io docker.io/dorowu/ubuntu-desktop-lxde-vnc Ubuntu with openssh-server and NoVNC on po... 20 [OK] docker.io docker.io/sequenceiq/hadoop-ubuntu An easy way to try Hadoop on Ubuntu 19 [OK] docker.io docker.io/tleyden5iwx/ubuntu-cuda Ubuntu 14.04 with CUDA drivers pre-installed 16 [OK] docker.io docker.io/ubuntu-debootstrap debootstrap --variant=minbase --components... 12 [OK] …
$ sudo docker images REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE docker.io/ubuntu latest 63e3c10217b8 7 days ago 188.3 MB docker.io/ubuntu 12.04 d0e008c6cf02 7 days ago 134.7 MB docker.google/etcd 2.1.1 2c319269dd15 8 days ago 23.32 MB docker.io/postgres latest 730d1d72bda2 2 weeks ago 265.3 MB …
7.20 push 参考
说明:将镜像上传到仓库
用法
Usage: docker push [OPTIONS] NAME[:TAG]
Push an image or a repository to the registry
-f, --force=false Push to public registry without confirmation --help=false Print usage
-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 --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
例子
$ sudo docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES b448f729a0b0 centos "/bin/bash" 4 days ago Exited (137) 4 days ago pensive_wilson 54c7b6d6632e centos "/bin/bash" 4 days ago Exited (0) 3 days ago adoring_wozniak
利用筛选器筛选出exied状态时0的容器:
$ sudo docker ps -a --filter 'exited=0' CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 8d92293a65e9 registry.liugang/centos "/bin/bash" 7 days ago Exited (0) 5 days ago web 8410f389ea65 registry.liugang/centos "/bin/bash" 7 days ago Exited (0) 7 days ago test_link
-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
$ sudo docker pauese hopeful_feynman hopeful_feynman CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES c9a12157fed7 centos "/bin/bash" 9 minutes ago Up 9 minutes (Paused) hopeful_feynman
-a, --attach=[] Attach to STDIN, STDOUT or STDERR --add-host=[] Add a custom host-to-IP mapping (host:ip) --blkio-weight=0 Block IO (relative weight), between 10 and 1000 -c, --cpu-shares=0 CPU shares (relative weight) --cap-add=[] Add Linux capabilities --cap-drop=[] Drop Linux capabilities --cgroup-parent= Optional parent cgroup for the container --cidfile= Write the container ID to the file --cpu-period=0 Limit CPU CFS (Completely Fair Scheduler) period --cpu-quota=0 Limit the CPU CFS quota --cpuset-cpus= CPUs in which to allow execution (0-3, 0,1) --cpuset-mems= MEMs in which to allow execution (0-3, 0,1) --device=[] Add a host device to the container --dns=[] Set custom DNS servers --dns-search=[] Set custom DNS search domains -e, --env=[] Set environment variables --entrypoint= Overwrite the default ENTRYPOINT of the image --env-file=[] Read in a file of environment variables --expose=[] Expose a port or a range of ports -h, --hostname= Container host name --help=false Print usage -i, --interactive=false Keep STDIN open even if not attached --init= Run container following specified init system container method (systemd) --ipc= IPC namespace to use -l, --label=[] Set meta data on a container --label-file=[] Read in a line delimited file of labels --link=[] Add link to another container --log-driver= Logging driver for container --log-opt=[] Log driver options --lxc-conf=[] Add custom lxc options -m, --memory= Memory limit --mac-address= Container MAC address (e.g. 92:d0:c6:0a:29:33) --memory-swap= Total memory (memory + swap), '-1' to disable swap --name= Assign a name to the container --net=bridge Set the Network mode for the container --oom-kill-disable=false Disable OOM Killer -P, --publish-all=false Publish all exposed ports to random ports -p, --publish=[] Publish a container's port(s) to the host --pid= PID namespace to use --privileged=false Give extended privileges to this container --read-only=false Mount the container's root filesystem as read only --restart=no Restart policy to apply when a container exits --security-opt=[] Security Options -t, --tty=false Allocate a pseudo-TTY -u, --user= Username or UID (format: <name|uid>[:<group|gid>]) --ulimit=[] Ulimit options --uts= UTS namespace to use -v, --volume=[] Bind mount a volume --volumes-from=[] Mount volumes from the specified container(s) -w, --workdir= Working directory inside the container
$ docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES a637c1d67506 ubuntu:latest "/bin/echo 'Hello wo 10 minutes ago Exited (0) 2 minutes ago mad_hopper
Usage: docker run [OPTIONS] IMAGE [COMMAND] [ARG...]
Run a command in a new container
-a, --attach=[] Attach to STDIN, STDOUT or STDERR --add-host=[] Add a custom host-to-IP mapping (host:ip) --blkio-weight=0 Block IO (relative weight), between 10 and 1000 -c, --cpu-shares=0 CPU shares (relative weight) --cap-add=[] Add Linux capabilities --cap-drop=[] Drop Linux capabilities --cgroup-parent= Optional parent cgroup for the container --cidfile= Write the container ID to the file --cpu-period=0 Limit CPU CFS (Completely Fair Scheduler) period --cpu-quota=0 Limit the CPU CFS quota --cpuset-cpus= CPUs in which to allow execution (0-3, 0,1) --cpuset-mems= MEMs in which to allow execution (0-3, 0,1) -d, --detach=false Run container in background and print container ID --device=[] Add a host device to the container --dns=[] Set custom DNS servers --dns-search=[] Set custom DNS search domains -e, --env=[] Set environment variables --entrypoint= Overwrite the default ENTRYPOINT of the image --env-file=[] Read in a file of environment variables --expose=[] Expose a port or a range of ports -h, --hostname= Container host name --help=false Print usage -i, --interactive=false Keep STDIN open even if not attached --init= Run container following specified init system container method (systemd) --ipc= IPC namespace to use -l, --label=[] Set meta data on a container --label-file=[] Read in a line delimited file of labels --link=[] Add link to another container --log-driver= Logging driver for container --log-opt=[] Log driver options --lxc-conf=[] Add custom lxc options -m, --memory= Memory limit --mac-address= Container MAC address (e.g. 92:d0:c6:0a:29:33) --memory-swap= Total memory (memory + swap), '-1' to disable swap --name= Assign a name to the container --net=bridge Set the Network mode for the container --oom-kill-disable=false Disable OOM Killer -P, --publish-all=false Publish all exposed ports to random ports -p, --publish=[] Publish a container's port(s) to the host --pid= PID namespace to use --privileged=false Give extended privileges to this container --read-only=false Mount the container's root filesystem as read only --restart=no Restart policy to apply when a container exits --rm=false Automatically remove the container when it exits --security-opt=[] Security Options --sig-proxy=true Proxy received signals to the process -t, --tty=false Allocate a pseudo-TTY -u, --user= Username or UID (format: <name|uid>[:<group|gid>]) --ulimit=[] Ulimit options --uts= UTS namespace to use -v, --volume=[] Bind mount a volume --volumes-from=[] Mount volumes from the specified container(s) -w, --workdir= Working directory inside the container
例子
用法与create类似,只是在创建容器后不需要进行start操作就可以运行。
$ sudo docker run ubuntu /bin/echo 'Hello world' Hello world $...
$ sudo docker run -d ubuntu /bin/sh -c "while true; do echo hello world; sleep 1; done" 61f37c1940c8ec9f08b107e99655b8a5181ded340415e3c15cf413069d556b73 $...
这时,我们查看一下容器状态:
$ sudo docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 61f37c1940c8 ubuntu:latest "/bin/sh -c 'while t 4 seconds ago Up 3 seconds prickly_galileo ...
查看容器输出的信息
$ sudo docker logs 61f37c1940c8 hello world hello world hello world hello world ...