Docker——常用命令(四)
本文只列舉了幾個常用的命令,其他命令可使用--help檢視或在網上自行查閱
一、檢視當前版本
命令:docker version 或者 docker -v[[email protected] ~]# docker version
Client version: 1.7.1
Client API version: 1.19
Go version (client): go1.4.2
Git commit (client): 786b29d/1.7.1
OS/Arch (client): linux/amd64
Server version: 1.7.1
Server API version: 1.19
Go version (server): go1.4.2
Git commit (server): 786b29d/1.7.1
OS/Arch (server): linux/amd64
[ [email protected] ~]# docker -v
Docker version 1.7.1, build 786b29d/1.7.1
[[email protected] ~]#
二、檢視當前所有docker映象
命令:docker images[[email protected] ~]# docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
[[email protected] ~]#
三、拉取遠端docker映象
命令:docker pull [OPTIONS] NAME[:TAG]
e.g.. docker pull hub.c.163.com/wangjiaen/centos6.9:ssh (從網易蜂巢拉取一個contos6.9的映象)
[[email protected] ~]# docker pull hub.c.163.com/wangjiaen/centos6.9:ssh
ssh: Pulling from hub.c.163.com/wangjiaen/centos6.9
ebe688773310: Pull complete
7d9a6cbcf4ff: Pull complete
48a89683e055: Pull complete
166c7265ea0d: Pull complete
5caf8ed79df7: Already exists
Digest: sha256:0d07d3e54a974c483c83dd64194718968b962e74c805833633fd12a5d0f31774
Status: Downloaded newer image for hub.c.163.com/wangjiaen/centos6.9:ssh
[ [email protected] ~]#
四、Docker的幫助命令
命令:docker COMMAND --help
e.g.. docker --help 、 docker run --help (列出docker的引數命令幫助、列出docker run的引數命令幫助)
[[email protected] ~]# docker run --help
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
--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
[[email protected] ~]#
五、執行docker映象
命令:docker run [OPTIONS] images[:TAG]
e.g.. docker run -d 5caf8ed (在後臺執行ID為5caf8ed的映象,注:-d為引數,指後臺執行且列印執行容器ID,5caf8ed為映象的ID前端部分,ID不一定要輸全,只要能夠區分開docker就知道要執行哪個)
[[email protected] ~]# docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
hub.c.163.com/wangjiaen/centos6.9 ssh 5caf8ed79df7 9 weeks ago 370.9 MB
[[email protected] ~]# docker run -d 5caf8ed
28d26a28befb16feb8506df458871a8416f1e9ae02e253d363fa4bba38180e6a
[[email protected] ~]#
六、檢視正在執行的容器
命令:docker ps
docker ps -a 列出所有容器
docker ps -l 最後建立的容器
其他引數不明白可以輸入:docker ps --help自行檢視(其他命令一樣,不懂就--help,以後就不贅述了)
[[email protected] ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
28d26a28befb 5caf8ed "/usr/sbin/sshd -D" 4 hours ago Up 4 hours 22/tcp cranky_wright
[[email protected] ~]#
七、進入容器內部
命令:docker exec [OPTIONS] CONTAINER COMMAND [ARG...]e.g.. docker exec -i -t IMAGE /bin/bash
e.g.. docker exec -it 28d bash (-it即-i -t ,以互動模式進入容器ID為:28d*的容器內部,bash即執行/bin/bash指令碼,如示例已經進入centos6.9內部)
[[email protected] ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
28d26a28befb 5caf8ed "/usr/sbin/sshd -D" 4 hours ago Up 4 hours 22/tcp cranky_wright
[[email protected] ~]# docker exec -it 28d bash
[[email protected] /]# ls
bin boot dev etc home lib lib64 media mnt opt proc root sbin selinux srv sys tmp usr var
[[email protected] /]#
八、退出容器
命令:exit
[[email protected] /]# ls
bin boot dev etc home lib lib64 media mnt opt proc root sbin selinux srv sys tmp usr var
[[email protected] /]# exit
exit
[[email protected] ~]#
九、停止正在執行的容器
命令:docker stop ContainerID
e.g.. docker stop 28d26a28befb (停止正在執行的ID為28d26a28befb的容器)
[[email protected] ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
28d26a28befb 5caf8ed "/usr/sbin/sshd -D" 4 hours ago Up 4 hours 22/tcp cranky_wright
[[email protected] ~]# docker stop 28d26a28befb
28d26a28befb
[[email protected] ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
[[email protected] ~]#
內鏈: