CentOS安装Docker
安装步骤
下载指定版本二进制离线包:https://download.docker.com/linux/static/stable/
# 例
wget https://download.docker.com/linux/static/stable/x86_64/docker-20.10.19.tgz
解压二进制压缩包
tar -zxvf docker-20.10.19.tgz
配置Docker用户
# 创建组
groupadd docker
# 添加Docker用户
useradd -g docker docker
# 设置密码
passwd docke
# 添加sudo权限:docker ALL=(ALL) ALL,增加一行
sudo visudo
将二进制文件移动到可执行文件目录
sudo cp docker/* /usr/bin/
注册systemctl自启
💁 通过yum、apt-get安装,在启动Docker后,会自动注册service,无需手动配置
# vim /etc/systemd/system/docker.service
# 创建docker.service文件,输入以下内容
[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network-online.target firewalld.service
Wants=network-online.target
[Service]
Type=notify
# the default is not to use systemd for cgroups because the delegate issues still
# exists and systemd currently does not support the cgroup feature set required
# for containers run by docker
ExecStart=/usr/bin/dockerd
ExecReload=/bin/kill -s HUP $MAINPID
# Having non-zero Limit*s causes performance problems due to accounting overhead
# in the kernel. We recommend using cgroups to do container-local accounting.
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity
# Uncomment TasksMax if your systemd version supports it.
# Only systemd 226 and above support this version.
#TasksMax=infinity
TimeoutStartSec=0
# set delegate yes so that systemd does not reset the cgroups of docker containers
Delegate=yes
# kill only the docker process, not all processes in the cgroup
KillMode=process
# restart the docker process if it exits prematurely
Restart=on-failure
StartLimitBurst=3
StartLimitInterval=60s
[Install]
WantedBy=multi-user.target
增加执行权限
chmod +x /etc/systemd/system/docker.service
加载配置
systemctl daemon-reload
启动Docker
systemctl start docker
# 查看状态
systemctl status docker
配置开机自启
systemctl enable docker.service
systemctl is-enabled docker.service
docker-compose安装
下载可执行文件:
# 更多版本参见:https://github.com/docker/compose/releases
wget https://github.com/docker/compose/releases/download/v2.24.2/docker-compose-linux-x86_64
移动到可执行文件目录
cp docker-compose-linux-x86_64 /usr/local/bin/docker-compose
添加可执行权限
chmod +x /usr/local/bin/docker-compose
验证是否可用
docker-compose -v
Windows安装Docker
安装步骤
- 安装Docker前确保 Linux 子系统已启用(控制面板 > 程序和功能)
- 下载Docker Desktop安装文件,历史版本下载地址:点击跳转
- 双击 Docker Desktop Install.exe,过程中默认点下一步即可。
- 安装完成后,点击桌面图标,进入Docker,左下方显示绿色则表示安装成功。
常见问题解决
WSL2 installation is incomplete
安装wsl_update后重启电脑