一、docker命令
1、docker help
docker command
Commands:
attach Attach local standard input, output, and error streams to a running container #当前shell下 attach 连接制定运行镜像
build Build an image from a Dockerfile #通过Dockerfile 定制镜像
commit Create a new image from a container's changes #提交当前容器为新的镜像
cp Copy files/folders between a container and the local filesystem #从容器中拷贝指定文件或者目录到宿主机中
create Create a new container #创建一个新的容器,同run,但不启动容器
diff Inspect changes to files or directories on a container's filesystem #查看docker容器变化
events Get real time events from the server #从docker服务获取容器实时事件
exec Run a command in a running container #在已存在的容器上运行命令
export Export a container's filesystem as a tar archive #导出容器的内容流作为一个tar归档文件,对应import
history Show the history of an image #展示一个镜像形成历史
images List images #列出系统当前镜像
import Import the contents from a tarball to create a filesystem image #从tar包中的内容创建一个新的文件系统映像,对应import
info Display system-wide information #显示系统相关信息
inspect Return low-level information on Docker objects #查看容器相关信息
kill Kill one or more running containers #kill指定的docker容器
load Load an image from a tar archive or STDIN #从一个tar包中家在一个镜像,对应sava
login Log in to a Docker registry #注册或者登录一个docker源服务器
logout Log out from a Docker registry #从当前 Docker registry退出
logs Fetch the logs of a container #输出当前容器日志信息
pause Pause all processes within one or more containers #暂停容器
port List port mappings or a specific mapping for the container #查看映射端口对应的容器内部源端口
ps List containers #列出容器列表
pull Pull an image or a repository from a registry #从docker镜像源服务器拉取指定镜像或者库镜像
push Push an image or a repository to a registry #推送指定镜像或者库镜像到docker源服务器
rename Rename a container #重命名一个镜像
restart Restart one or more containers #重启运行的容器
rm Remove one or more containers #移除一个或者多个容器
rmi Remove one or more images #移除一个或者多个镜像(无容器使用该镜像才可删除,否则需删除相关容器才可继续或者-f 强制删除)
run Run a command in a new container #创建一个新的容器并运行一个命令
save Save one or more images to a tar archive (streamed to STDOUT by default) #保存一个镜像为tar包,对应load
search Search the Docker Hub for images #在docker hub中搜索镜像
start Start one or more stopped containers #启动容器
stats Display a live stream of container(s) resource usage statistics #显示容器使用的系统资源
stop Stop one or more running containers #停止容器
tag Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE #给源中镜像打标签
top Display the running processes of a container #查看容器中运行的进程信息
unpause Unpause all processes within one or more containers #取消暂停容器
update Update configuration of one or more containers #更新一个或者多个容器的配置
version Show the Docker version information #查看docker版本号
wait Block until one or more containers stop, then print their exit codes #截取容器停止时的退出状态值
Run 'docker COMMAND --help' for more information on a command.
docker option
Usage of docker:
--api-enable-cors=false Enable CORS headers in the remote API # 远程 API 中开启 CORS 头
-b, --bridge="" Attach containers to a pre-existing network bridge # 桥接网络
use 'none' to disable container networking
--bip="" Use this CIDR notation address for the network bridge's IP, not compatible with -b
# 和 -b 选项不兼容,具体没有测试过
-d, --daemon=false Enable daemon mode # daemon 模式
-D, --debug=false Enable debug mode # debug 模式
--dns=[] Force docker to use specific DNS servers # 强制 docker 使用指定 dns 服务器
--dns-search=[] Force Docker to use specific DNS search domains # 强制 docker 使用指定 dns 搜索域
-e, --exec-driver="native" Force the docker runtime to use a specific exec driver # 强制 docker 运行时使用指定执行驱动器
--fixed-cidr="" IPv4 subnet for fixed IPs (ex: 10.20.0.0/16)
this subnet must be nested in the bridge subnet (which is defined by -b or --bip)
-G, --group="docker" Group to assign the unix socket specified by -H when running in daemon mode
use '' (the empty string) to disable setting of a group
-g, --graph="/var/lib/docker" Path to use as the root of the docker runtime # 容器运行的根目录路径
-H, --host=[] The socket(s) to bind to in daemon mode # daemon 模式下 docker 指定绑定方式[tcp or 本地 socket]
specified using one or more tcp://host:port, unix:///path/to/socket, fd://* or fd://socketfd.
--icc=true Enable inter-container communication # 跨容器通信
--insecure-registry=[] Enable insecure communication with specified registries (no certificate verification for HTTPS and enable HTTP fallback) (e.g., localhost:5000 or 10.20.0.0/16)
--ip="0.0.0.0" Default IP address to use when binding container ports # 指定监听地址,默认所有 ip
--ip-forward=true Enable net.ipv4.ip_forward # 开启转发
--ip-masq=true Enable IP masquerading for bridge's IP range
--iptables=true Enable Docker's addition of iptables rules # 添加对应 iptables 规则
--mtu=0 Set the containers network MTU # 设置网络 mtu
if no value is provided: default to the default route MTU or 1500 if no default route is available
-p, --pidfile="/var/run/docker.pid" Path to use for daemon PID file # 指定 pid 文件位置
--registry-mirror=[] Specify a preferred Docker registry mirror
-s, --storage-driver="" Force the docker runtime to use a specific storage driver # 强制 docker 运行时使用指定存储驱动
--selinux-enabled=false Enable selinux support # 开启 selinux 支持
--storage-opt=[] Set storage driver options # 设置存储驱动选项
--tls=false Use TLS; implied by tls-verify flags # 开启 tls
--tlscacert="/root/.docker/ca.pem" Trust only remotes providing a certificate signed by the CA given here
--tlscert="/root/.docker/cert.pem" Path to TLS certificate file # tls 证书文件位置
--tlskey="/root/.docker/key.pem" Path to TLS key file # tls key 文件位置
--tlsverify=false Use TLS and verify the remote (daemon: verify client, client: verify daemon) # 使用 tls 并确认远程控制主机
-v, --version=false Print version information and quit # 输出 docker 版本信息
2、docker命令实例(命令太多不做一一演示)
2.1 docker search
$ docker search --filter=stars=100 ubuntu
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
ubuntu Ubuntu is a Debian-based Linux operating sys… 9085 [OK]
dorowu/ubuntu-desktop-lxde-vnc Ubuntu with openssh-server and NoVNC 263 [OK]
rastasheep/ubuntu-sshd Dockerized SSH service, built on top of offi… 197 [OK]
consol/ubuntu-xfce-vnc Ubuntu container with "headless" VNC session… 151 [OK]
2.2 docker pull && docker push
docker pull ubuntu # 下载官方 ubuntu docker 镜像,默认下载所有 ubuntu 官方库镜像
docker pull ubuntu:14.04 # 下载指定版本 ubuntu 官方镜像
docker push 192.168.0.100:5000/ubuntu # 推送镜像库到私有源[可注册 docker 官方账户,推送到官方自有账户]
docker push 192.168.0.100:5000/ubuntu:14.04 # 推送指定镜像到私有源
2.3 docker images
$docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
web latest 464ca63bbb18 20 hours ago 109MB
nginx latest 7042885a156a 2 weeks ago 109MB
2.4 docker run
$docker run -t -i -c 100 -m 512MB -h test1 -d --name="docker_test1" ubuntu /bin/bash # 创建一个 cpu 优先级为 100,内存限制 512MB,主机名为 test1,名为 docker_test1 后台运行 bash 的容器 a424ca613c9f2247cd3ede95adfbaf8d28400cbcb1d5f9b69a7b56f97b2b52e5 $ sudo docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a424ca613c9f ubuntu:14.04 /bin/bash 6 seconds ago Up 5 seconds docker_test1 $ sudo docker attach docker_test1
2.5 docker start|stop|kill|restart…
2.6 docker load |save
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
web latest 464ca63bbb18 21 hours ago 109MB
nginx latest 7042885a156a 2 weeks ago 109MB
ccs-iMac:~ cc$ docker save 464c -o ~/web.tar
ccs-iMac:~ cc$ docker load -i web.tar