安装 Docker。此处不使用 https://get.docker.com
一键脚本;另外,将安装源改成阿里,原生源是 AWS,国内太慢。
yum install -y yum-utils device-mapper-persistent-data lvm2 \
&& yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo \
&& sed -i 's/download.docker.com/mirrors.aliyun.com\/docker-ce/g' /etc/yum.repos.d/docker-ce.repo \
&& yum install docker-ce
一些基础配置。新建或者编辑 /etc/docker/daemon.json
文件,内容如下。
{
"bip": "10.10.0.1/16",
"live-restore": true,
"registry-mirrors": [
"https://hub-mirror.c.163.com",
"https://docker.mirrors.ustc.edu.cn",
"https://reg-mirror.qiniu.com"
]
}
bip
是自定义 docker0 网卡的网段,按实际情况修改或删除,详见此链接。
live-restore
是指停止或重启 docker 守护进程(daemon) 时不影响运行中的容器(container),详见此链接。
registry-mirrors 就是镜像源了,此处使用 docker 中国的镜像源;这个镜像源不是山寨的,详见此链接。
docker-cn 凉了,现在换成了 Azure 和 七牛。
Azure 只给自己人用了;七牛下线了 镜像中心,虽然 reg-mirror
还能访问,但是心里总是怕怕的。新增了网易和 USTC,观望七牛。
不喜欢阿里云那种登录后查看系统分配系统的,此处不考虑。
启动!
systemctl enable docker \
&& systemctl start docker
查看 docker 信息:
docker info
如果出现警告:
WARNING: bridge-nf-call-iptables is disabled
WARNING: bridge-nf-call-ip6tables is disabled
执行:
sysctl net.bridge.bridge-nf-call-iptables=1 \
&& sysctl net.bridge.bridge-nf-call-ip6tables=1
如果需要升级 Docker,使用下面第一条命令查看现有版本,然后使用第二条命令安装。
yum list docker-ce --showduplicates | sort -r
yum install docker-ce-<VERSION STRING>
前面使用 bip
自定义 docker0
的网段,但 docker-compose 启动的容器并不受此配置影响,希望自定义容器网段的话,见以下 docker-compose.yml 示例文件,详见此链接。
version: "3.6"
services:
# 该部分省略
networks:
default:
driver: bridge
ipam:
driver: default
config:
- subnet: 10.11.0.1/16