Docker 从 17.03 版本之后分为 CE(Community Edition 社区版)和 EE(Enterprise Edition 企业版)两个版本。
https://blog.docker.com/2017/03/docker-enterprise-edition/
这里安装 CE 版本。
使用脚本安装
curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun
一、安装
卸载旧版本
sudo yum remove docker docker-client docker-client-latest docker-common docker-latest docker-latest-logrotate docker-logrotate docker-engine
安装
# step 1: 安装必要的一些系统工具 sudo yum install -y yum-utils # Step 2: 添加软件源信息(阿里源:https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo,daocloud 源:https://download.daocloud.io/docker/linux/centos/docker-ce.repo) sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo sudo yum-config-manager --disable docker-ce-test sudo yum-config-manager --disable docker-ce-nightly # Step 3: 安装 Docker-CE sudo yum -y install docker-ce docker-ce-cli containerd.io # Step 4: 开启 Docker 服务 sudo systemctl start docker # Step 5: 开机自启 sudo systemctl enable docker # Step 6: 安装校验 sudo docker version
将当前用户添加至 docker 用户组(加入 docker 用户组后非 root 用户可以不用 sudo 启动 docker)
# 添加 docker 用户组 sudo groupadd docker # 将当前登陆用户加入到 docker 用户组中 sudo gpasswd -a $USER docker # 更新用户组 sudo newgrp docker
二、切换镜像源
daemon.json 配置说明:https://docs.docker.com/engine/reference/commandline/dockerd/#daemon-configuration-file
关于守护进程:https://docs.docker.com/config/daemon/
以网易为例,创建或修改 /etc/docker/daemon.json 文件(默认没有该文件)
sudo mkdir -p /etc/docker sudo tee /etc/docker/daemon.json << EOF { "registry-mirrors": ["https://82m9ar63.mirror.aliyuncs.com", "https://hub-mirror.c.163.com"] } EOF # 重启服务 sudo systemctl daemon-reload sudo systemctl restart docker # 查看当前配置信息 docker info
其它源
中国科技大学 https://docker.mirrors.ustc.edu.cn 阿里云(需注册) https://cr.console.aliyun.com/ 华为云(需注册) https://mirrors.huaweicloud.com/ https://registry.docker-cn.com # 腾讯云 docker hub 镜像 https://mirror.ccs.tencentyun.com # DaoCloud 镜像 http://f1361db2.m.daocloud.io # 华为云镜像 https://05f073ad3c0010ea0f4bc00b7105ec20.mirror.swr.myhuaweicloud.com # 阿里云 docker hub 镜像 https://registry.cn-hangzhou.aliyuncs.com
测试
docker run hello-world
三、安装 docker-compose
yum 安装(可能不是最新版本),需要 epel 源:https://developer.aliyun.com/mirror/epel
mv /etc/yum.repos.d/epel.repo /etc/yum.repos.d/epel.repo.backup mv /etc/yum.repos.d/epel-testing.repo /etc/yum.repos.d/epel-testing.repo.backup wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo yum install docker-compose -y
下载安装(最新版)
# 要安装不同版本的 Compose,请将 1.29.2 替换为想要使用的 Compose 版本 # 原地址:sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose sudo curl -L "https://get.daocloud.io/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose sudo chmod +x /usr/local/bin/docker-compose sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose docker-compose --version # docker-compose version 1.29.2, build 5becea4c
四、Windows WSL2 安装 Docker
安装与上面一样,这里记录一些问题
# WSL Debian Docker 启动失败 # https://superuser.com/questions/1468316/which-kernel-moduules-are-really-needed-for-docker-installation sudo update-alternatives --set iptables /usr/sbin/iptables-legacy sudo update-alternatives --set ip6tables /usr/sbin/ip6tables-legacy # grep: /etc/fstab: No such file or directory sudo touch /etc/fstab # 重启 docker sudo service docker restart sudo service docker status # 有些容器启动失败可能是文件权限问题 # https://blog.csdn.net/x356982611/article/details/108732844 # https://docs.microsoft.com/zh-cn/windows/wsl/wsl-config#per-distribution-configuration-options-with-wslconf sudo vim /etc/wsl.conf [automount] enabled = true options = "metadata" mountFsTab = false # 重启 wsl(windows 命令) # https://docs.microsoft.com/zh-cn/windows/wsl/basic-commands#shutdown wsl --shutdown
https://docs.docker.com/engine/install/centos
https://docs.docker.com/compose/install
https://www.daocloud.io/mirror
https://help.aliyun.com/document_detail/60750.html
https://developer.aliyun.com/article/110806