本文只列举了几个常用的命令,其他命令可使用--help查看或在网上自行查阅
一、查看当前版本
[root@localhost ~]# 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
[root@localhost ~]# docker -v
Docker version 1.7.1, build 786b29d/1.7.1
[root@localhost ~]#
二、查看当前所有docker镜像
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
[root@localhost ~]#
三、拉取远程docker镜像
网易蜂巢docker镜像库地址:https://c.163.com/hub#/m/home/
命令:docker pull [OPTIONS] NAME[:TAG]
e.g.. docker pull hub.c.163.com/wangjiaen/centos6.9:ssh (从网易蜂巢拉取一个contos6.9的镜像)
[root@localhost ~]# 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
[root@localhost ~]#
四、Docker的帮助命令
命令:docker COMMAND --help
e.g.. docker --help 、 docker run --help (列出docker的参数命令帮助、列出docker run的参数命令帮助)
[root@localhost ~]# 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
[root@localhost ~]#
五、运行docker镜像
命令:docker run [OPTIONS] images[:TAG]
e.g.. docker run -d 5caf8ed (在后台运行ID为5caf8ed的镜像,注:-d为参数,指后台运行且打印运行容器ID,5caf8ed为镜像的ID前端部分,ID不一定要输全,只要能够区分开docker就知道要运行哪个)
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
hub.c.163.com/wangjiaen/centos6.9 ssh 5caf8ed79df7 9 weeks ago 370.9 MB
[root@localhost ~]# docker run -d 5caf8ed
28d26a28befb16feb8506df458871a8416f1e9ae02e253d363fa4bba38180e6a
[root@localhost ~]#
六、查看正在运行的容器
命令:docker ps
docker ps -a 列出所有容器
docker ps -l 最后创建的容器
其他参数不明白可以输入:docker ps --help自行查看(其他命令一样,不懂就--help,以后就不赘述了)
[root@localhost ~]# 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
[root@localhost ~]#
七、进入容器内部
命令: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内部)
[root@localhost ~]# 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
[root@localhost ~]# docker exec -it 28d bash
[root@28d26a28befb /]# ls
bin boot dev etc home lib lib64 media mnt opt proc root sbin selinux srv sys tmp usr var
[root@28d26a28befb /]#
八、退出容器
命令:exit
[root@28d26a28befb /]# ls
bin boot dev etc home lib lib64 media mnt opt proc root sbin selinux srv sys tmp usr var
[root@28d26a28befb /]# exit
exit
[root@localhost ~]#
九、停止正在运行的容器
命令:docker stop ContainerID
e.g.. docker stop 28d26a28befb (停止正在运行的ID为28d26a28befb的容器)
[root@localhost ~]# 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
[root@localhost ~]# docker stop 28d26a28befb
28d26a28befb
[root@localhost ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
[root@localhost ~]#
内链:
Docker——给tomcat容器部署项目并且做成新的镜像(容器内外拷贝)(六)