文章目录
🍇安装docker
有旧版本执行如下命令卸载:
yum remove -y docker\
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-engine
# 1、yum 包更新到最新
yum update
# 2、安装需要的软件包, yum-util 提供yum-config-manager功能,另外两个是devicemapper驱动依赖的
yum install -y yum-utils device-mapper-persistent-data lvm2
# 3、 设置yum源
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
# 4、 安装docker,出现输入的界面都按 y
yum install -y docker-ce
# 5、 查看docker版本,验证是否验证成功docker -v
🍈启动、停止、重启Docker
sudo systemctl start dockersudo systemctl stop dockersudo systemctl restart docker
🍉Docker配置文件
修改配置文件
/etc/docker/daemon.json
,进入/etc/docker目录。查看是否有daemon.json文件,没有则执行如下命令创建。
touch daemon.json
文件内容配置如下:
{"registry-mirrors":["https://jkfdsf2u.mirror.aliyuncs.com","https://registry.docker-cn.com"],"insecure-registries":["docker-registry.zjq.com"],"log-driver":"json-file","log-opts":{"max-size":"10m","max-file":"10"},"data-root":"/data/docker"}
配置说明:
{
#镜像源管理,我增加了阿里镜像源,可以提速
"registry-mirrors":["https://jkfdsf2u.mirror.aliyuncs.com","https://registry.docker-cn.com"],
#docker私服配置,因为不是https链接,所以在此配置
"insecure-registries":["docker-registry.zjq.com"],
#日志最大存储限制,如果不配置它,可能会导致/var/lib/docker/tmp/containers目录中的容器日志过大,挤占系统盘空间。
"log-driver":"json-file","log-opts":{"max-size":"10m","max-file":"10"},
#Docker运行时使用的根路径,默认 "/var/lib/docker""data-root":"/data/docker"}
除了上述配置,其他的我采取默认,更多配置可以查看官方:https://docs.docker.com/engine/reference/commandline/dockerd/#daemon-configuration-file
文件配置完成后执行如下命令重新加载,并重启docker
sudo systemctl daemon-reload
sudo systemctl restart docker
🍊配置 Docker 阿里镜像加速器
- 镜像(Image):Docker 镜像(Image),就相当于是一个 root 文件系统。比如官方镜像 ubuntu:16.04 就包含了完整的一套 Ubuntu16.04 最小系统的 root 文件系统。
- 容器(Container):镜像(Image)和容器(Container)的关系,就像是面向对象程序设计中的类和对象一样,镜像是静态的定义,容器是镜像运行时的实体。容器可以被创建、启动、停止、删除、暂停等。
- 仓库(Repository):仓库可看成一个代码控制中心,用来保存镜像。
- 进入阿里云官网https://www.aliyun.com/,检索 容器镜像服务
- 按照官方说明设置镜像加速器
https://cr.console.aliyun.com/cn-hangzhou/instances/mirrors
🍋daemon.json完整配置说明
{
#用一组新的注册表替换守护程序将向其推送不可分发工件的注册表集
"allow-nondistributable-artifacts":[],"api-cors-header":"",
#指定要使用的授权插件
"authorization-plugins":[],"bip":"",
#标志设置docker0为默认桥接网络
"bridge":"","cgroup-parent":"","cluster-advertise":"",
#使用新地址重新加载发现存储。
"cluster-store":"",
#使用新选项重新加载发现存储。
"cluster-store-opts":{},"containerd":"/run/containerd/containerd.sock","containerd-namespace":"docker","containerd-plugin-namespace":"docker-plugins","data-root":"",
#当设置为 true 时,它将守护程序更改为调试模式
"debug":true,"default-address-pools":[{"base":"172.30.0.0/16","size":24},{"base":"172.31.0.0/16","size":24}],"default-cgroupns-mode":"private","default-gateway":"","default-gateway-v6":"","default-runtime":"runc","default-shm-size":"64M","default-ulimits":{"nofile":{"Hard":64000,"Name":"nofile","Soft":64000}},
#设定容器DNS的地址,在容器的 /etc/resolv.conf文件中可查看
"dns":[],"dns-opts":[],
#设定容器的搜索域
"dns-search":[],"exec-opts":[],"exec-root":"","experimental":false,
#明确启用或禁用特定功能
"features":{},"fixed-cidr":"","fixed-cidr-v6":"","group":"","hosts":[],"icc":false,"init":false,"init-path":"/usr/libexec/docker-init","insecure-registries":[],"ip":"0.0.0.0","ip-forward":false,"ip-masq":false,
#阻止 Docker 守护进程添加 iptables 规则
"iptables":false,"ip6tables":false,"ipv6":false,
#docker主机的标签,很实用的功能,例如定义:–label nodeName=host-121"labels":[],
#启用在守护进程停机期间保持容器活动
"live-restore":true,
#Default driver for container logs(default"json-file")"log-driver":"json-file","log-level":"",
#日志配置
"log-opts":{"cache-disabled":"false","cache-max-file":"5","cache-max-size":"20m","cache-compress":"true","env":"os,customer","labels":"somelabel","max-file":"5","max-size":"10m"},
#每次拉取的最大并发下载量
"max-concurrent-downloads":3,
#每次推送的最大并发上传量
"max-concurrent-uploads":5,
#每次拉取的最大下载尝试次数
"max-download-attempts":5,"mtu":0,"no-new-privileges":false,"node-generic-resources":["NVIDIA-GPU=UUID1","NVIDIA-GPU=UUID2"],"oom-score-adjust":-500,"pidfile":"","raw-logs":false,
#镜像源管理
"registry-mirrors":[],
#可用于运行容器的可用OCI运行时列表
"runtimes":{"cc-runtime":{"path":"/usr/bin/cc-runtime"},"custom":{"path":"/usr/local/bin/my-runc-replacement","runtimeArgs":["--debug"]}},"seccomp-profile":"",
#默认 false,启用selinux支持
"selinux-enabled":false,"shutdown-timeout":15,"storage-driver":"","storage-opts":[],"swarm-default-advertise-addr":"",
#启动TLS认证开关
"tls":true,"tlscacert":"","tlscert":"","tlskey":"","tlsverify":true,"userland-proxy":false,"userland-proxy-path":"/usr/libexec/docker-proxy","userns-remap":""}
相关文章:
Windows10系统安装docker
添加docker权限给其他用户使用
版权归原作者 共饮一杯无 所有, 如有侵权,请联系我们删除。