犀渠玉剑良家子,白马金羁侠少年。这篇文章主要讲述Docker 环境初始化安装相关的知识,希望能为你提供帮助。
?安装docker?
参考官网:https://docs.docker.com/engine/install/centos/
1.移除本机的docker(防止有老的docker):
sudo yum remove docker \\
docker-client \\
docker-client-latest \\
docker-common \\
docker-latest \\
docker-latest-logrotate \\
docker-logrotate \\
docker-engine
2.安装yum-utils,添加docker yum源
sudo yum install -y yum-utils
sudo yum-config-manager \\
--add-repo \\
https://download.docker.com/linux/centos/docker-ce.repo
3.安装docker
sudo yum install docker-ce docker-ce-cli containerd.io
?配置docker 镜像加速器?
个人注册个阿里云的账号,进入容器服务。
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json < < -EOF
"registry-mirrors": ["https://4z7jtuuf.mirror.aliyuncs.com"]
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker
?修改docker 的存储根目录?
docker 根的默认路径是/var/lib/docker
?参数:"data-root": "/data",?
[root@harbor ~]# cat /etc/docker/daemon.json
"registry-mirrors": ["https://v16stybc.mirror.aliyuncs.com"],
"insecure-registries": ["https://testharbor.sit.51zhaoyou.com"],
"exec-opts": ["native.cgroupdriver=systemd"],
"data-root": "/data",
"log-driver": "json-file",
"log-opts":
"max-size":"100m"
自定义安全dockcer仓库?
简单解释就是改为自己或者公司的私有仓库,然后不需要认证登录下载。
官网链接:https://docs.docker.com/registry/insecure/
?参数:"insecure-registries": ["https://testharbor.sit.51zhaoyou.com"],不定义默认获取https://hub.docker.com/?
?设置docker守护进程参数?
?live-restore重载docker守护进程而不重启容器。需要结合--restart=always,否则重启docker容器就down了。?
"live-restore": true
[root@harbor < sub> ]# docker run -itd--restart=always --name nginx nginx:latest
a897ce1045a2085de0f8fea36315287571c4bb824b5f624ff0d8fa3db247e891
[root@harbor < /sub> ]# docker ps
CONTAINER IDIMAGECOMMANDCREATEDSTATUSPORTSNAMES
a897ce1045a2nginx:latest"/docker-entrypoint.…"3 seconds agoUp 2 seconds80/tcpnginx
[root@harbor < sub> ]# vim /etc/docker/daemon.json
[root@harbor < /sub> ]# systemctl restart docker
[root@harbor ~]# docker ps
CONTAINER IDIMAGECOMMANDCREATEDSTATUSPORTSNAMES
a897ce1045a2nginx:latest"/docker-entrypoint.…"24 seconds agoUp 22 seconds80/tcpnginx
?修改docker dns配置?
?参数:"dns": ["114.114.114.114","8.8.8.8"],只对配置后的新容器生效,之前的容器不生效。
配置前
[root@harbor < sub> ]# docker ps
CONTAINER IDIMAGECOMMANDCREATEDSTATUSPORTSNAMES
a897ce1045a2nginx:latest"/docker-entrypoint.…"5 minutes agoUp 5 minutes80/tcpnginx
[root@harbor < /sub> ]# docker exec -it nginx cat /etc/resolv.conf
# Generated by NetworkManager
nameserver 192.168.1.1
nameserver 192.168.0.1
配置后
[root@harbor < sub> ]# cat /etc/docker/daemon.json
"registry-mirrors": ["https://v16stybc.mirror.aliyuncs.com"],
"insecure-registries": ["https://testharbor.sit.51zhaoyou.com"],
"exec-opts": ["native.cgroupdriver=systemd"],
"dns": ["114.114.114.114","8.8.8.8"],
"data-root": "/data",
"log-driver": "json-file",
"live-restore": true,
"log-opts":
"max-size":"100m"
[root@harbor < /sub> ]# systemctl restart docker
[root@harbor ~]# docker exec -it nginx cat /etc/resolv.conf
# Generated by NetworkManager
nameserver 192.168.1.1
nameserver 192.168.0.1
新增容器启动查看dns解析
[root@harbor < sub> ]# docker run -itd--restart=always --name redis redis:latest
Unable to find image redis:latest locally
latest: Pulling from library/redis
a2abf6c4d29d: Already exists
c7a4e4382001: Pull complete
4044b9ba67c9: Pull complete
c8388a79482f: Pull complete
413c8bb60be2: Pull complete
1abfd3011519: Pull complete
Digest: sha256:db485f2e245b5b3329fdc7eff4eb00f913e09d8feb9ca720788059fdc2ed8339
Status: Downloaded newer image for redis:latest
e01e4204dd570e055fdce1a435714a1a407ac1f374d79fc35c49a57864a82c75
[root@harbor < /sub> ]# docker exec -it redis cat /etc/resolv.conf
nameserver 114.114.114.114
nameserver 8.8.8.8
【Docker 环境初始化安装】
推荐阅读
- linux文件属性及类型
- Linux 内核进程管理 task_struct 结构体 ⑤ ( files 字段 | nsproxy 字段 | 信号处理相关字段 | 信号量和共享内存相关字段 )
- Linux 内核进程管理 task_struct 结构体 ③ ( real_parent 字段 | parent 字段 | group_leader 字段 | real_credcred字段 )
- #yyds干货盘点#剑指 Offer 11. 旋转数组的最小数字
- 玩转算法复杂度
- kubectl 命令(陈述式)
- 关于在JVS的基础上企业内部私有化红头文件实现的思考
- vivo 商品中台的可视化微前端实践
- C语言实现“三子棋”小游戏