1, docker image download
docker pull [options] name [:tag@digest]
name behind the label can now mirror or mirrored Summary (in fact mirrored version), if not anything, it will default download docker hub in: latest (latest edition)
Parameter details:
name |
default |
description |
--all-tags, a |
|
Download all mirrors warehouse |
--disable-content-trust |
true |
Skip verification Mirror |
--platform |
|
Set mirror-owned platform , if there are multiple mirror service . |
2, view the current docker mirror
docker images [options] [repository[:tag]]
images can be added behind the image name and version you want to see
3, run-time image
docker run [options] image [:tag] [command] [arg...]
Recommended : docker run -dit [id]
Parameter Description:
-d, --detach = false , the specified container running in the foreground or background, the default is false
-i, --interactive = false , open STDIN, for interactive console
-t, --tty = false , distribution tty device, which can support the terminal login, default is false
-u, --user = "" , the user specifies the container
-a, --attach = [] , log in container (must be based docker run -d initiated container)
-w, --workdir = "" , specified container working directory
-C, --cpu-shares = 0 , provided the container CPU weight, using the CPU sharing scenario
-e, --env = [] , the specified environment variable, the container can be used in the environment variables
-m, --memory = "" , specifies the memory limit container
-P, = All---publish to false , the specified container is exposed to port
-p, --publish = [] , the specified container port exposed
-h, --hostname = "" , the host name of the specified container
-v, = --volume [] , to mount the storage volume of the container, the container mount of a directory
= from---volumes [] , to mount the container volume on other containers, the container mounted to a directory
= the Add---cap [] , add permissions, see the list of permissions: http://linux.die.net/man/7/capabilities
= drop---cap [] , delete permissions, see the list of permissions: http://linux.die.net/man/7/capabilities
= --cidfile "" , run the container, the container is written in the specified file PID values, a typical usage monitoring system
= --cpuset "" , provided the container may be used which the CPU, that parameter may be used to monopolize the CPU container
= --device [] , is added to the vessel a host device, through the device corresponds to
= - DNS [] , the specified container dns server
Search-= - DNS [] , the specified container dns domain search, writing to the container file /etc/resolv.conf
= --entrypoint "" , covering the image entry point
File-= --env [] , the specified environment variable file, a file format environment variable for each row
= --expose [] , the specified container port exposed, i.e., exposed to modify the port mirroring
= --link [] , the association between the specified container, other containers IP, env and other information
--lxc-conf=[], 指定容器的配置文件,只有在指定--exec-driver=lxc时使用
--name="", 指定容器名字,后续可以通过名字进行容器管理,links特性需要使用名字
--net="bridge", 容器网络设置:
bridge 使用docker daemon指定的网桥
host //容器使用主机的网络
container:NAME_or_ID >//使用其他容器的网路,共享IP和PORT等网络资源
none 容器使用自己的网络(类似--net=bridge),但是不进行配置
--privileged=false, 指定容器是否为特权容器,特权容器拥有所有的capabilities
--restart="no", 指定容器停止后的重启策略:
no:容器退出时不重启
on-failure:容器故障退出(返回值非零)时重启
always:容器退出时总是重启
--rm=false, 指定容器停止后自动删除容器(不支持以docker run -d启动的容器)
--sig-proxy=true, 设置由代理接受并处理信号,但是SIGCHLD、SIGSTOP和SIGKILL不能被代理
4、查看正在运行的docker容器
docker ps
-a :显示所有的容器,包括未运行的。
-q :静默模式,只显示容器编号。
-f :根据条件过滤显示的内容。
--format :指定返回值的模板文件。
-l :显示最近创建的容器。
-n :列出最近创建的n个容器。
--no-trunc :不截断输出。
-s :显示总的文件大小。
5、进入docker容器内部的shell
docker exec -it [name] bash
-d,以后台方式执行命令;
-e,设置环境变量
-i,交互模式
-t,设置TTY
-u,用户名或UID,例如myuser:myusergroup
6、docker build 构建镜像
docker build [OPTIONS] PATH | URL | -
OPTIONS说明:
-f :指定要使用的Dockerfile路径;
-m :设置内存最大值;
--tag, -t: 镜像的名字及标签,通常 name:tag 或者 name 格式;可以在一次构建中为一个镜像设置多个标签。
--build-arg=[] :设置镜像创建时的变量;
--cpu-shares :设置 cpu 使用权重;
--cpu-period :限制 CPU CFS周期;
--cpu-quota :限制 CPU CFS配额;
--cpuset-cpus :指定使用的CPU id;
--cpuset-mems :指定使用的内存 id;
--disable-content-trust :忽略校验,默认开启;
--force-rm :设置镜像过程中删除中间容器;
--isolation :使用容器隔离技术;
--label=[] :设置镜像使用的元数据;
--memory-swap :设置Swap的最大值为内存+swap,"-1"表示不限swap;
--no-cache :创建镜像的过程不使用缓存;
--pull :尝试去更新镜像的新版本;
--quiet, -q :安静模式,成功后只输出镜像 ID;
--rm :设置镜像成功后删除中间容器;
--shm-size :设置/dev/shm的大小,默认值是64M;
--ulimit :Ulimit配置。
--network: 默认 default。在构建期间设置RUN指令的网络模式
7、docker删除容器
(1)首先查看系统现有的容器
docker ps -a
很多是测试产生的容器,现在将他们删除,执行:
docker rm [c9b077c1e8b2 97b22f5efeca]
c9b077c1e8b2、97b22f5efeca为要删除容器的id
(2)删除正在运行中的容器
此时id为 ae32dddeadbf 的容器正在运行中
我们直接删除它是会报错的:
这时加上参数 -f (强制删除)即可
docker rm -f ae32dddeadbf
(3)删除所有的容器
先停止所有运行中的容器:
docker stop $(docker ps -q)
再查看所有的容器:
docker ps -aq
删除所有的容器:
docker rm $(docker ps -aq)
8、docker删除镜像
先查看当前镜像:
docker images
删除镜像:
docker rmi ceshicopy2
ok,已经删除
需要注意的是,删除镜像时,必须保证没有容器正在基于此镜像运行着,所以需要先删除基于此镜像的容器,再删除镜像
9、docker镜像的导入导出
先查看当前镜像
docker images
(1)docker镜像的导出
docker save
用法:docker save > 【目标文件】 【源镜像名】
示例:
docker save > nginx.tar hub.c.163.com/library/nginx
(2)docker镜像的导入
docker load
用法:docker load < 【导入的镜像】
示例:
docker load < nginx.tar
10、docker容器的导入导出
查看当前容器
docker ps -a
(1)容器的导出
docker export
用法:docker export > 【目标文件】 【源镜像名】
示例:
docker export > jpress.tar 8bf49fa5ca97
(2)容器的导入
docker import
用法:docker import 【导入的容器】 【导入后修改的名字】
示例:
docker import jpress.tar jpress:1
注意:
容器导入后也会形成镜像,然后再运行此镜像即可!
11、保存修改后的容器内容
docker commit [容器id] [修改后的名字:tag]
示例:
docker commit 03b79d8cef9d jpmysql
已经生成新的镜像,基于修改后的容器。
直接运行即可
12、镜像上传至私有仓库
docker push [OPTIONS] NAME[:TAG]
示例:
1、首先登录docker hub
docker login
2、上传镜像
docker push runningrookie/ubuntu:16.04
注意:上传此镜像前,需要先把镜像的名称改为[用户名]/ubuntu:[tag]格式,前边一定要是自己登录账号的用户名;
注意:[用户名]表示你的用户名,/ubuntu表示这个叫ubuntu的存储库,后边的:[tag]才是你上传到docker hub后显示的标签名称。
3、进入docker hub查看
13、docker容器设置开机自启
1、用法:
启动时加--restart=always参数
2、示例:
docker run --restart=always .....
如果创建时未指定 --restart=always ,可通过update 命令设置:
docker update --restart=always xxx
若想要关闭自启动,可执行
docker update --restart=no xxx
3、参数:
no 不自动重启容器. (默认值)
on-failure 容器发生error而退出(容器退出状态不为0)重启容器,可以指定重启的最大次数,如:on-failure:10
unless-stopped 在容器已经stop掉或Docker stoped/restarted的时候才重启容器
always 在容器已经stop掉或Docker stoped/restarted的时候才重启容器,手动stop的不算