【Docker笔记】Docker安装及配置

【Docker笔记】Docker安装及配置_第1张图片

文章目录

  • CentOS安装Docker
    • 安装步骤
    • docker-compose安装
  • Windows安装Docker
    • 安装步骤
    • 常见问题解决
      • WSL2 installation is incomplete


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

安装步骤

  1. 安装Docker前确保 Linux 子系统已启用(控制面板 > 程序和功能
    【Docker笔记】Docker安装及配置_第2张图片
  2. 下载Docker Desktop安装文件,历史版本下载地址:点击跳转
  3. 双击 Docker Desktop Install.exe,过程中默认点下一步即可。
  4. 安装完成后,点击桌面图标,进入Docker,左下方显示绿色则表示安装成功。
    【Docker笔记】Docker安装及配置_第3张图片

常见问题解决

WSL2 installation is incomplete

【Docker笔记】Docker安装及配置_第4张图片

安装wsl_update后重启电脑

你可能感兴趣的:(Docker,docker,笔记)