Docker是一个开源的应用容器引擎,让开发者可以打包他们的应用以及依赖包到一个可移植的容器中,然后发布到任何流行的Linux机器上,也可以实现虚拟化,容器是完全使用沙箱机制,相互之间不会有任何接口。
个完整的Docker有以下几个部分组成:
- Docker Client 客户端
- Docker Daemon 守护进程
- Docker Image 镜像
- Docker Container 容器
Docker功能特性
1隔离环境(系统,网络,文件系统)与应用
2解决依赖与版本问题
3易于分发
4节点与容器快速扩容
5制作简单,管理方便
Docker的安装
安装环境
最小化安装Centos7.5 关闭防火墙和selinux
#安装依赖包 yum -y install yum-utils device-mapper-persistent-data lvm2 #添加docker的CE版本的yum源配置文件 curl https://download.docker.com/linux/centos/docker-ce.repo -o /etc/yum.repos.d/docker-ce.repo #如果不能下载 自行创建 #安装CE版本的docker yum -y install docker-ce systemctl start docker #启动docker systemctl disable docker #添加开机启动 docker version #查看docker版本 docker version Client: Version: 18.06.1-ce API version: 1.38 Go version: go1.10.3 Git commit: e68fc7a Built: Tue Aug 21 17:23:03 2018 OS/Arch: linux/amd64 Experimental: false Server: Engine: Version: 18.06.1-ce API version: 1.38 (minimum version 1.12) Go version: go1.10.3 Git commit: e68fc7a Built: Tue Aug 21 17:25:29 2018 OS/Arch: linux/amd64 Experimental: false
vim /etc/yum.repos.d/docker-ce.repo #docker repo文件
[docker-ce-stable]
name=Docker CE Stable - $basearch
baseurl=https://download.docker.com/linux/centos/7/$basearch/stable
enabled=1
gpgcheck=1
gpgkey=https://download.docker.com/linux/centos/gpg
[docker-ce-stable-debuginfo]
name=Docker CE Stable - Debuginfo $basearch
baseurl=https://download.docker.com/linux/centos/7/debug-$basearch/stable
enabled=0
gpgcheck=1
gpgkey=https://download.docker.com/linux/centos/gpg
[docker-ce-stable-source]
name=Docker CE Stable - Sources
baseurl=https://download.docker.com/linux/centos/7/source/stable
enabled=0
gpgcheck=1
gpgkey=https://download.docker.com/linux/centos/gpg
[docker-ce-edge]
name=Docker CE Edge - $basearch
baseurl=https://download.docker.com/linux/centos/7/$basearch/edge
enabled=0
gpgcheck=1
gpgkey=https://download.docker.com/linux/centos/gpg
[docker-ce-edge-debuginfo]
name=Docker CE Edge - Debuginfo $basearch
baseurl=https://download.docker.com/linux/centos/7/debug-$basearch/edge
enabled=0
gpgcheck=1
gpgkey=https://download.docker.com/linux/centos/gpg
[docker-ce-edge-source]
name=Docker CE Edge - Sources
baseurl=https://download.docker.com/linux/centos/7/source/edge
enabled=0
gpgcheck=1
gpgkey=https://download.docker.com/linux/centos/gpg
[docker-ce-test]
name=Docker CE Test - $basearch
baseurl=https://download.docker.com/linux/centos/7/$basearch/test
enabled=0
gpgcheck=1
gpgkey=https://download.docker.com/linux/centos/gpg
[docker-ce-test-debuginfo]
name=Docker CE Test - Debuginfo $basearch
baseurl=https://download.docker.com/linux/centos/7/debug-$basearch/test
enabled=0
gpgcheck=1
gpgkey=https://download.docker.com/linux/centos/gpg
[docker-ce-test-source]
name=Docker CE Test - Sources
baseurl=https://download.docker.com/linux/centos/7/source/test
enabled=0
gpgcheck=1
gpgkey=https://download.docker.com/linux/centos/gpg
[docker-ce-nightly]
name=Docker CE Nightly - $basearch
baseurl=https://download.docker.com/linux/centos/7/$basearch/nightly
enabled=0
gpgcheck=1
gpgkey=https://download.docker.com/linux/centos/gpg
[docker-ce-nightly-debuginfo]
name=Docker CE Nightly - Debuginfo $basearch
baseurl=https://download.docker.com/linux/centos/7/debug-$basearch/nightly
enabled=0
gpgcheck=1
gpgkey=https://download.docker.com/linux/centos/gpg
[docker-ce-nightly-source]
name=Docker CE Nightly - Sources
baseurl=https://download.docker.com/linux/centos/7/source/nightly
enabled=0
gpgcheck=1
gpgkey=https://download.docker.com/linux/centos/gpg
Docker的操作命令
添加docker国内镜像源
我们首先要更改一下docker的默认源镜像下载地址(默认是从国外下载,很慢),我们需要添加国内的源地址
vim /etc/docker/daemon.json { "registry-mirrors":[ "https://registry.docker-cn.com" ] } systemctl daemon-reload systemctl restart docker
Docker命令:
-
search 用于从docker的官方公有镜像仓库查找镜像
-
pull 用于从Docker Hub上下载公有镜像
-
images 用于本地镜像的查看
-
build 用于本地自定义镜像的构建,需要创建Dockerfile文件
-
run 运行一个本地镜像
-
ps 查看已经运行的镜像的进程
-
attach 从本地系统中切入到某个STATUS状态是UP的镜像进程里
-
stop 用于停止一个正在运行着的容器进程
-
start 用于启动一个已经停止了的容器进程
-
rm 用于删除一个已经停止了的容器进程
-
rmi 用于删除一个未用作容器启动的本地镜像
-
commit 将一个更改过的容器进程的容器状态保存为一个新的镜像
-
exec 用于从本地操作系统上直接向容器进程发布执行命令并返回结果
-
cp 用于在容器进程和本地系统之间复制文件
-
create 用于创建一个容器进程,但是并不启动它
-
diff 查看容器进程与源镜像做对比,发生了改变的文件或文件夹
-
events 时时监测容器的变化情况
-
export 将容器进程的文件系统导出到本地
-
import 用于将export导出的文件系统创建为一个镜像
-
history 用于查看一个镜像的历史修改纪录
-
info 用于查看当前操作系统的docker运行信息
-
inspect 查看某个镜像的详细信息
-
kill 强行停止一个或多个正在运行状态的容器进程
-
save 用于将一个镜像的文件系统导出到本地(export导出的是容器)
-
load 用于将save导出到本地的tar包,重新加载为镜像(和源镜像的名字标识完全一样)
-
logs 用于输出一个容器进程内的操作日志
-
pause && unpause 用于将一个或多个容器的进程暂停和恢复
-
port 用于列出一个容器的端口映射及协议
-
rename 给容器进程重命名
-
restart 重启一个容器进程
-
stats 用于时时输出容器的资源使用情况
-
tag 用于从一个指定的镜像创建另外一个镜像
-
top 用于显示指定容器的进程信息
-
update 用于调整一个或多个容器的启动配置
-
version and wait version用于显示docker的版本信息 wait用于捕捉一个或多个容器的退出状态,并返回退出状态码
命令详解
search用于从docker的官方公有镜像仓库查找镜像
docker search centos #查看centos镜像 NAME DESCRIPTION STARS OFFICIAL AUTOMATED centos The official build of CentOS. 4659 [OK] ansible/centos7-ansible Ansible on Centos7 115 [OK] jdeathe/centos-ssh CentOS-6 6.10 x86_64 / CentOS-7 7.5.1804 x86… 99 [OK] 特别说明: Name:镜像的名字 DESCRIPTION:描述 STARS:星级(越高越好) OFFICIAL:是否是官方发布的 AUTOMATED:是否自动化的
#多条件查找--filter=-f
docker search centos --filter is-official=true -f stars=100
官方发布的 星级大于100的
pull 用于从Docker Hub上下载公有镜像
#下载目标centos镜像 docker pull centos:7
images 用于本地镜像的查看
docker images REPOSITORY TAG IMAGE ID CREATED SIZE centos 7 5182e96772bf 4 weeks ago 200MB 特别说明: REPOSITORY:镜像仓库(下边罗列的都是本地已有镜像名称) TAG:镜像的标记(为了区分同名镜像) IMAGES ID:镜像的ID号 CREATED:此镜像的创建时间 SIZE:此镜像的大小
build 用于本地自定义镜像的构建,需要创建Dockerfile文件
#创建Dockerfile文件的存储目录 mkdir -p /root/dockerfile/lib/centos/7 cd /root/dockerfile/lib/centos/7 vim docker.sh #!/bin/bash while true do echo "welcome" sleep 5 done #创建Dockerfile配置文件,文件名称必须为Dockerfile,第一个字母必须大写 vim Dockerfile FROM centos #从centos源镜像的基础上进行构建 LABEL MAINTATNER="wk" #作者的名称 RUN ln -sfv /usr/share/zoneinfo/Asia/Shanghai /etc/localtime #RUN:在镜像构建过程中运行命令 ADD docker.sh /home/test/ #从本地系统中把docker.sh文件添加到构建中的镜像的/home/test/目录下 RUN chmod +x /home/test/docker.sh #在镜像构建过程中运行命令 CMD ["/home/test/docker.sh"] #构建镜像完成时,最后执行的命令 #根据Dockfile配置文件构建一个自定义镜像 docker build -t wk/centos7:1 . #-t 指定镜像名称 :1 设定镜像的tag标记 .在当前目录下 Sending build context to Docker daemon 207.9MB Step 1/6 : FROM centos ---> 5182e96772bf Step 2/6 : LABEL MAINTATNER="Mr.chen.com" ---> Running in 8394eb3581bc Removing intermediate container 8394eb3581bc ---> 765c759b0485 Step 3/6 : RUN ln -sfv /usr/share/zoneinfo/Asia/Shanghai /etc/localtime ---> Running in b6af26ceb921 '/etc/localtime' -> '/usr/share/zoneinfo/Asia/Shanghai' Removing intermediate container b6af26ceb921 ---> 7f8c6f739092 Step 4/6 : ADD docker.sh /home/test/ ---> b236f6cfe485 Step 5/6 : RUN chmod +x /home/test/docker.sh ---> Running in 2104d69e389e Removing intermediate container 2104d69e389e ---> 15a56f49cc47 Step 6/6 : CMD ["/home/test/docker.sh"] ---> Running in a34a9cb8a9e6 Removing intermediate container a34a9cb8a9e6 ---> 21067d2780f3 Successfully built 21067d2780f3 #构建成功 Successfully tagged wk/centos7:1 docker images REPOSITORY TAG IMAGE ID CREATED SIZE wk/centos7 1 21067d2780f3 30 seconds ago 200MB centos 7 5182e96772bf 4 weeks ago 200MB
run 运行一个本地镜像
ocker images REPOSITORY TAG IMAGE ID CREATED SIZE wk/centos7 1 21067d2780f3 3 minutes ago 200MB centos 7 5182e96772bf 4 weeks ago 200MB docker run 2106 #2106 取IMAGE ID的前4位,只要ID能作为唯一标识就能使用 welcome welcome welcome docker run -dit 2106 /bin/bash
特别提示: docker run:运行一个指定的images id -d:放在后台运行 -i:可以进行命令交互 -t:制作一个伪终端用于登陆
21067d2780f3:镜像的ID,可以简写成2106
ps 查看已经运行的镜像的进程
docker ps -a #不加-a只显示运行的,加-a显示所有 CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES bf3bb800e44b 2106 "/bin/bash" 2 minutes ago Up 2 minutes goofy_stonebraker 特别提示: STATUS:进程的状态,UP表示正在运行中,EXIT表示已经退出了。
attach 从本地系统中切入到某个STATUS状态是UP的镜像进程里
docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES bf3bb800e44b 2106 "/bin/bash" 2 minutes ago Up 2 minutes goofy_stonebraker [root@wk 7]# docker attach bf3b #切入到容器号为bf3b的镜像进程里 [root@bf3bb800e44b /]# exit #退出容器 exit [root@wk 7]# docker ps -a #容器的进程的STATUS已经处于EXIT状态(之前是后台运行的,切入进去后执行exit就等于手动退出了) CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES bf3bb800e44b 2106 "/bin/bash" 4 minutes ago Exited (0) 6 seconds ago goofy_stonebraker
stop /start 用于停止和启动一个正在运行着的容器进程
docker ps -a #查看当前容器状态 CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES bf3bb800e44b 2106 "/bin/bash" 7 minutes ago Exited (0) 2 minutes ago goofy_stonebraker
docker start bf3b #启动bf3b容器 bf3b
docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES bf3bb800e44b 2106 "/bin/bash" 7 minutes ago Up 1 second goofy_stonebraker
docker stop bf3b #关闭bf3b容器 bf3b
docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES bf3bb800e44b 2106 "/bin/bash" 8 minutes ago Exited (137) 1 second ago goofy_stonebraker
rm和 rmi 用于删除一个已经停止了的容器进程和用于删除一个未用作容器启动的本地镜像
#rmi镜像的删除需要先rm删除镜像所创建的容器
docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES bf3bb800e44b 2106 "/bin/bash" 12 minutes ago Exited (137) 4 minutes ago goofy_stonebraker docker rm bf3b #注意运行中的容器进程需要先stop,才能删除 bf3b docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES docker images REPOSITORY TAG IMAGE ID CREATED SIZE wk/centos7 1 21067d2780f3 21 minutes ago 200MB centos 7 5182e96772bf 4 weeks ago 200MB centos latest 5182e96772bf 4 weeks ago 200MB docker rmi -f 2106 #-f 强制删除(即便被占用)但要注意,被用作容器启动的镜像是不能删除的(需先rm删除容器进程) Untagged: wk/centos7:1 Deleted: sha256:21067d2780f3b3a714654f97291d1cff9cb13d0f32a6fdfa921c212f18c8132c Deleted: sha256:15a56f49cc47603e5bb14ab10c2f64c71ba601940a201e7b367d4878e0822ae0 Deleted: sha256:441963cd30c126ce52369ca1ca37789dd643b456205c8625f8fd174e1d47933b Deleted: sha256:b236f6cfe4850dc4d24283755565f88a54b157c91fa344e21ef41d5cd3a48d0e Deleted: sha256:4fbf8d060514a9a3efc6f468b3abcb8ef7a732b4b91aeef977a5f684511237ef Deleted: sha256:7f8c6f73909270ae17f31b7e68c90682a71ded4cad3d0ce31f5357bbe75365be Deleted: sha256:96a90795aa833b6d95d6f546e1219b2d660540a73802b3bec7a4c87d5072aba6 Deleted: sha256:765c759b0485fd835dc1fbee9c69b199f19e801bad8c99e3c683fd83a283f237 docker images REPOSITORY TAG IMAGE ID CREATED SIZE centos 7 5182e96772bf 4 weeks ago 200MB centos latest 5182e96772bf 4 weeks ago 200MB
commit 将一个更改过的容器进程的容器状态保存为一个新的镜像
docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 31719a59fd35 5182 "/bin/bash" 10 seconds ago Up 9 seconds fervent_albattani docker commit 31719 wk.centos:1 #将容器进程保存为一个新的镜像 sha256:aeebe2fd33f864575451c1e8b93750bd002504c039a345c12c18e40b39c39454 docker images REPOSITORY TAG IMAGE ID CREATED SIZE wk.centos 1 aeebe2fd33f8 48 seconds ago 200MB #新保存的镜像 centos 7 5182e96772bf 4 weeks ago 200MB centos latest 5182e96772bf 4 weeks ago 200MB
exec 用于从本地操作系统上直接向容器进程发布执行命令并返回结果
docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 31719a59fd35 5182 "/bin/bash" 4 minutes ago Up 4 minutes fervent_albattani
docker exec 317 ls /root #查看容器进程里/root的所有文件 anaconda-ks.cfg
docker exec 317 ls /tmp #查看容器进程里/tmp的所有文件
ks-script-Lu6hIQ yum.log
docker exec -it 317 /bin/bash #进入docker容器命令
cp 用于在容器进程和本地系统之间复制文件
docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 31719a59fd35 5182 "/bin/bash" 8 minutes ago Up 8 minutes fervent_albattani
docker cp 317:/etc/passwd . #将指定容器进程317的/etc/passwd复制到当前目录下
ls Dockerfile docker.sh passwd test.tar #复制成功
docker cp test.tar 317:/root #将本地文件test.tar 复制到容器317的/root下
docker exec 317 ls /root #复制成功
anaconda-ks.cfg test.tar
create 用于创建一个容器进程,但是并不启动它
docker images REPOSITORY TAG IMAGE ID CREATED SIZE wk.centos 1 aeebe2fd33f8 11 minutes ago 200MB centos 7 5182e96772bf 4 weeks ago 200MB centos latest 5182e96772bf 4 weeks ago 200MB docker create -it 518 #创建一个镜像的容器进程,但不直接启动 95d9ede337e836c0089c1e85285352b6aab06d5dd9d040e41cdaef4c033b045f
docker ps -a #Created创建状态并未启动 CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 95d9ede337e8 518 "/bin/bash" 19 seconds ago Created gallant_pare 31719a59fd35 5182 "/bin/bash" 14 minutes ago Up 14 minutes fervent_albattani
diff 查看容器进程与源镜像做对比,发生了改变的文件或文件夹
docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 95d9ede337e8 518 "/bin/bash" 19 seconds ago Created gallant_pare 31719a59fd35 5182 "/bin/bash" 14 minutes ago Up 14 minutes fervent_albattani docker diff 317 #查看容器317进程与镜像的变化 C /root A /root/test.tar
events 时时监测容器的变化情况
docker events
export和impore export将容器进程的文件系统导出到本地 import 将""export''导出的文件系统创建为一个镜像
docker export 317 > test.tar #将容器进程317导出成一个tar包
ls Dockerfile docker.sh passwd test.tar
docker import test.tar wk/centos:3 #将导出的tar包文件系统生成一个新的镜像 sha256:bf4bb485e391872790d4bdf4b3068360cd45fb01f9cac29770611e113c794004
docker images REPOSITORY TAG IMAGE ID CREATED SIZE wk/centos 3 bf4bb485e391 17 seconds ago 200MB wk.centos 1 aeebe2fd33f8 22 minutes ago 200MB centos 7 5182e96772bf 4 weeks ago 200MB centos latest 5182e96772bf 4 weeks ago 200MB
save 用于将一个镜像的文件系统导出到本地(export导出的是容器) load 用于将save导出到本地的tar包,重新加载为镜像(和源镜像的名字标识完全一样)
[root@wk 7]# docker images #查看镜像 REPOSITORY TAG IMAGE ID CREATED SIZE centos 7 5182e96772bf 4 weeks ago 200MB [root@wk 7]# docker save centos:7 > hehe.tar #镜像导出用名字和TAG导出 [root@wk 7]# docker rmi 518 #删除原镜像 Untagged: centos:7 Untagged: centos@sha256:6f6d986d425aeabdc3a02cb61c02abb2e78e57357e92417d6d58332856024faf Deleted: sha256:5182e96772bf11f4b912658e265dfe0db8bd314475443b6434ea708784192892 Deleted: sha256:1d31b5806ba40b5f67bde96f18a181668348934a44c9253b420d5f04cfb4e37a [root@wk 7]# docker load < hehe.tar #重新导入之前导出的镜像 1d31b5806ba4: Loading layer [==================================================>] 208.3MB/208.3MB Loaded image: centos:7 [root@wk 7]# docker images #导入成功和原镜像完全一样 REPOSITORY TAG IMAGE ID CREATED SIZE centos 7 5182e96772bf 4 weeks ago 200MB
history 用于查看一个镜像的历史修改纪录
docker history 镜像名
info 用于查看当前操作系统的docker运行信息
docker info Containers: 2 #容器进程2个 Running: 1 #正在运行状态的容器1个 Paused: 0 Stopped: 1 #停止容器1个 Images: 3 #一共有3个镜像 Server Version: 18.06.1-ce Storage Driver: overlay2 Backing Filesystem: xfs
inspect 查看某个镜像的详细信息
docker inspect 镜像名
kill 强行停止一个或多个正在运行状态的容器进程
docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 31719a59fd35 5182 "/bin/bash" 32 minutes ago Up 32 minutes fervent_albattani
docker kill 317 317
docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 31719a59fd35 5182 "/bin/bash" 33 minutes ago Exited (137) 8 seconds ago fervent_albattani
logs 用于输出一个容器进程内的操作日志
docker logs 容器ID
pause && unpause 用于将一个或多个容器的进程暂停和恢复
[root@wk 7]# docker pause 9e db #暂停9e容器和db容器 9e db
[root@wk 7]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 9e90abe9c524 518 "/bin/bash" 43 seconds ago Up 43 seconds (Paused) flamboyant_feynman db9fdb501a3a 518 "/bin/bash" About a minute ago Up About a minute (Paused) vigilant_brattain
[root@wk 7]# docker unpause 9e db #恢复9e容器和db容器 9e db
[root@wk 7]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 9e90abe9c524 518 "/bin/bash" About a minute ago Up About a minute flamboyant_feynman db9fdb501a3a 518 "/bin/bash" 2 minutes ago Up 2 minutes vigilant_brattain
port 用于列出一个容器的端口映射及协议
docker images REPOSITORY TAG IMAGE ID CREATED SIZE centos 7 5182e96772bf 4 weeks ago 200MB docker run -dit -p 8555:22 518 #启动一个镜像518为容器,将本地端口8555映射到镜像端口22 ccc9d58fa6e6437489078cd3f5513988796de4b66697ed0c5d687f340942afe6 docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES ccc9d58fa6e6 518 "/bin/bash" 14 seconds ago Up 13 seconds 0.0.0.0:8555->22/tcp elastic_bardeen 9e90abe9c524 518 "/bin/bash" 6 minutes ago Up 6 minutes flamboyant_feynman db9fdb501a3a 518 "/bin/bash" 7 minutes ago Up 7 minutes vigilant_brattain
docker port ccc #查看容器ccc的映射端口 22/tcp -> 0.0.0.0:8555
rename 给容器进程重命名
docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES ccc9d58fa6e6 518 "/bin/bash" 2 minutes ago Up 2 minutes 0.0.0.0:8555->22/tcp elastic_bardeen 9e90abe9c524 518 "/bin/bash" 8 minutes ago Up 8 minutes flamboyant_feynman db9fdb501a3a 518 "/bin/bash" 9 minutes ago Up 9 minutes vigilant_brattain
docker rename elastic_bardeen wk #将容器ccc的名字elastic_bardeen改为wk
docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES ccc9d58fa6e6 518 "/bin/bash" 3 minutes ago Up 3 minutes 0.0.0.0:8555->22/tcp wk 9e90abe9c524 518 "/bin/bash" 9 minutes ago Up 9 minutes flamboyant_feynman db9fdb501a3a 518 "/bin/bash" 10 minutes ago Up 10 minutes vigilant_brattain
restart 重启一个容器进程
docker restart ccc #重启容器ccc
ccc
stats 用于时时输出容器的资源使用情况
docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 02e7612375e7 518 "/bin/bash" 3 minutes ago Up 3 minutes distracted_villani docker stats 02e #时时刷新状态 CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS 02e7612375e7 distracted_villani 0.00% 380KiB / 2.077GiB 0.02% 1.3kB / 0B 9.59MB / 0B 1 docker stats 02e --no-stream #--no-stream只输出一次 CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS 02e7612375e7 distracted_villani 0.00% 380KiB / 2.077GiB 0.02% 1.3kB / 0B 9.59MB / 0B 1
top 用于显示指定容器的进程信息
docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 02e7612375e7 518 "/bin/bash" 9 minutes ago Up 9 minutes distracted_villani docker top 02e UID PID PPID C STIME TTY TIME CMD root 1611 1595 0 21:16 pts/0 00:00:00 /bin/bash
tag 用于从一个指定的镜像创建另外一个镜像
docker images REPOSITORY TAG IMAGE ID CREATED SIZE centos 7 5182e96772bf 4 weeks ago 200MB
docker tag centos:7 centos:1 #指定centos:TAG7创建centos:TAG1
docker images REPOSITORY TAG IMAGE ID CREATED SIZE centos 1 5182e96772bf 4 weeks ago 200MB centos 7 5182e96772bf 4 weeks ago 200MB
docker tag 5182e centos:3 #也可以指定IMAGE ID来创建
docker images REPOSITORY TAG IMAGE ID CREATED SIZE centos 1 5182e96772bf 4 weeks ago 200MB centos 3 5182e96772bf 4 weeks ago 200MB centos 7 5182e96772bf 4 weeks ago 200MB
update 用于调整一个或多个容器的启动配置
docker update --help Usage: docker update [OPTIONS] CONTAINER [CONTAINER...] Update configuration of one or more containers Options: --blkio-weight uint16 Block IO (relative weight), between 10 and 1000, or 0 to disable (default 0) --cpu-period int Limit CPU CFS (Completely Fair Scheduler) period --cpu-quota int Limit CPU CFS (Completely Fair Scheduler) quota --cpu-rt-period int Limit the CPU real-time period in microseconds --cpu-rt-runtime int Limit the CPU real-time runtime in microseconds -c, --cpu-shares int CPU shares (relative weight) #调整CPU --cpus decimal Number of CPUs --cpuset-cpus string CPUs in which to allow execution (0-3, 0,1) --cpuset-mems string MEMs in which to allow execution (0-3, 0,1) --kernel-memory bytes Kernel memory limit -m, --memory bytes Memory limit #调整内存 --memory-reservation bytes Memory soft limit --memory-swap bytes Swap limit equal to memory plus swap: '-1' to enable unlimited swap --restart string Restart policy to apply when a container exits
version and wait version用于显示docker的版本信息 wait用于捕捉一个或多个容器的退出状态,并返回退出状态码
docker version Client: Version: 18.06.1-ce API version: 1.38 Go version: go1.10.3 Git commit: e68fc7a Built: Tue Aug 21 17:23:03 2018 OS/Arch: linux/amd64 Experimental: false Server: Engine: Version: 18.06.1-ce API version: 1.38 (minimum version 1.12) Go version: go1.10.3 Git commit: e68fc7a Built: Tue Aug 21 17:25:29 2018 OS/Arch: linux/amd64 Experimental: false
docker wait 容器ID