Docker 使用技巧(Cent OS)
1. docker 倉庫添加(阿里云)
# 安裝 yum-utils
yum install -y yum-utils
# 添加 docker 倉庫
yum-config-manager \
--add-repo \
http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
2. docker 安裝指定版本
# 查詢可用版本
yum list docker-ce --showduplicates | sort -r
# 安裝指定版本
yum install docker-ce-18.09.9-3.el7
# 啟動docker
systemctl start docker
# 版本驗證
docker version
3. docker 鏡像加速
# 添加鏡像源
cat > /etc/docker/daemon.json << EOF
{
"registry-mirrors": [
"https://registry.docker-cn.com",
"http://hub-mirror.c.163.com",
"https://docker.mirrors.ustc.edu.cn"
]
}
EOF
# 加載重啟docker
systemctl daemon-reload && systemctl restart docker
4. docker 創(chuàng)建自定義網(wǎng)絡
# 創(chuàng)建 10.10.88.0/16 名為 mynetwork 的網(wǎng)絡
docker network create --subnet 10.10.88.0/16 mynetwork
5. docker 創(chuàng)建固定 IP 容器
# 創(chuàng)建自定義網(wǎng)絡
# 創(chuàng)建固定IP容器
docker run -itd --net mynetwork --ip 10.10.88.22 nginx