# docker --help 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=[] Daemon socket(s) to connect to -h, --help=false Print usage -l, --log-level=info Set the logging level --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 Commands: attach Attach to a running container
--將終端依附到容器上 1> 運行一個交互型容器 [root@localhost ~]# docker run -i -t centos /bin/bash [root@f0a02b473067 /]# 2> 在另外一個窗口上查看該容器的狀態 [root@localhost ~]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES d4a75f165ce6 centos "/bin/bash" 5 seconds ago Up 5 seconds cranky_mahavira 3> 退出第一步中運行的容器 [root@d4a75f165ce6 /]# exit exit 4> 查看該容器的狀態 [root@localhost ~]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES d4a75f165ce6 centos "/bin/bash" 2 minutes ago Exited (0) 23 seconds ago cranky_mahavira 可見此時容器的狀態是Exited,那麼,如何再次運行這個容器呢?可使用docker start命令 5> 再次運行該容器 [root@localhost ~]# docker start cranky_mahavira cranky_mahavira 6> 再次查看該容器的狀態 [root@localhost ~]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES d4a75f165ce6 centos "/bin/bash" 6 minutes ago Up 29 seconds cranky_mahavira 由於該容器是交互型的,但此刻咱們發現沒有具體的終端能夠與之交互,這時可以使用attach命令。 7> 經過attach命令進行交互 [root@localhost ~]# docker attach cranky_mahavira [root@d4a75f165ce6 /]#
build Build an image from a Dockerfile --經過Dockerfile建立鏡像
commit Create a new image from a container's changes --經過容器建立本地鏡像 注意:若是是要push到docker hub中,注意生成鏡像的命名 [root@localhost ~]# docker commit centos_v1 centos:v1 68ad49c999496cff25fdda58f0521530a143d3884e61bce7ada09bdc22337638 [root@localhost ~]# docker push centos:v1 You cannot push a "root" repository. Please rename your repository to <user>/<repo> (ex: <user>/centos) 用centos:v1就不行,由於它push到docker hub中時,是推送到相應用戶下,必須指定用戶名。譬如個人用戶名是ivictor,則新生成的本地鏡像命名爲: docker push victor/centos:v1,其中v1是tag,可不寫,默認是latest
cp Copy files/folders from a container to a HOSTDIR or to STDOUT --在宿主機和容器之間相互COPY文件 cp的用法以下: Usage: docker cp [OPTIONS] CONTAINER:PATH LOCALPATH|- docker cp [OPTIONS] LOCALPATH|- CONTAINER:PATH 如:容器mysql中/usr/local/bin/存在docker-entrypoint.sh文件,可以下方式copy到宿主機
# docker cp mysql:/usr/local/bin/docker-entrypoint.sh /root
修改完畢後,將該文件從新copy回容器
# docker cp /root/docker-entrypoint.sh mysql:/usr/local/bin/
create Create a new container
--建立一個新的容器,注意,此時,容器的status只是Created
diff Inspect changes on a container's filesystem --查看容器內發生改變的文件,以個人mysql容器爲例 [root@localhost ~]# docker diff mysqldb C /root A /root/.bash_history A /test1.txt A /test.tar A /test.txt C /run C /run/mysqld A /run/mysqld/mysqld.pid A /run/mysqld/mysqld.sock 不難看出,C對應的均是目錄,A對應的均是文件
events Get real time events from the server --實時輸出Docker服務器端的事件,包括容器的建立,啓動,關閉等。 譬如: [root@localhost ~]# docker events 2015-09-08T17:40:13.000000000+08:00 d2a2ef5ddb90b505acaf6b59ab43eecf7eddbd3e71f36572436c34dc0763db79: (from wordpress) create 2015-09-08T17:40:14.000000000+08:00 d2a2ef5ddb90b505acaf6b59ab43eecf7eddbd3e71f36572436c34dc0763db79: (from wordpress) die 2015-09-08T17:42:10.000000000+08:00 839866a338db6dd626fa8eabeef53a839e4d2e2eb16ebd89679aa722c4caa5f7: (from mysql) start
exec Run a command in a running container --用於容器啓動以後,執行其它的任務 經過exec命令能夠建立兩種任務:後臺型任務和交互型任務 後臺型任務:docker exec -d cc touch 123 其中cc是容器名 交互型任務: [root@localhost ~]# docker exec -i -t cc /bin/bash root@1e5bb46d801b:/# ls 123 bin boot dev etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var
export Export a container's filesystem as a tar archive --將容器的文件系統打包成tar文件 有兩種方式: docker export -o mysqldb1.tar mysqldb docker export mysqldb > mysqldb.tar
history Show the history of an image --顯示鏡像製做的過程,至關於dockfile
images List images
--列出本機的全部鏡像
import Import the contents from a tarball to create a filesystem image --根據tar文件的內容新建一個鏡像,與以前的export命令相對應 [root@localhost ~]# docker import mysqldb.tar mysql:v1 eb81de183cd94fd6f0231de4ff29969db822afd3a25841d2dc9cf3562d135a10 [root@localhost ~]# docker images REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE mysql v1 eb81de183cd9 21 seconds ago 281.9 MB
info Display system-wide information --查看docker的系統信息 [root@localhost ~]# docker info Containers: 3 --當前有3個容器 Images: 298 Storage Driver: devicemapper Pool Name: docker-253:0-34402623-pool Pool Blocksize: 65.54 kB Backing Filesystem: xfs Data file: /dev/loop0 Metadata file: /dev/loop1 Data Space Used: 8.677 GB --對應的是下面Data loop file大小 Data Space Total: 107.4 GB Data Space Available: 5.737 GB Metadata Space Used: 13.4 MB --對應的是下面Metadata loop file大小 Metadata Space Total: 2.147 GB Metadata Space Available: 2.134 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: 2 Total Memory: 979.7 MiB Name: localhost.localdomain ID: TFVB:BXGQ:VVOC:K2DJ:LECE:2HNK:23B2:LEVF:P3IQ:L7D5:NG2V:UKNL WARNING: bridge-nf-call-iptables is disabled WARNING: bridge-nf-call-ip6tables is disabled
inspect Return low-level information on a container or image --用於查看容器的配置信息,包含容器名、環境變量、運行命令、主機配置、網絡配置和數據卷配置等。
kill Kill a running container --強制終止容器 關於stop和kill的區別,docker stop命令給容器中的進程發送SIGTERM信號,默認行爲是會致使容器退出,固然, 容器內程序能夠捕獲該信號並自行處理,例如能夠選擇忽略。而docker kill則是給容器的進程發送SIGKILL信號,該信號將會使容器必然退出。
load Load an image from a tar archive or STDIN --與下面的save命令相對應,將下面sava命令打包的鏡像經過load命令導入
login Register or log in to a Docker registry --登陸到本身的Docker register,需有Docker Hub的註冊帳號 [root@localhost ~]# docker login Username: ivictor Password: Email: xxxx@foxmail.com WARNING: login credentials saved in /root/.docker/config.json Login Succeeded
logout Log out from a Docker registry --退出登陸 [root@localhost ~]# docker logout Remove login credentials for https://index.docker.io/v1/
logs Fetch the logs of a container --用於查看容器的日誌,它將輸出到標準輸出的數據做爲日誌輸出到docker logs命令的終端上。經常使用於後臺型容器