Centos8安装Docker

Centos8安装Docker

      • 一、环境
      • 二、互联网环境
        • 2.1 环境配置
        • 2.2 安装docker
      • 三、无互联网环境
        • 3.1 环境配置
        • 3.2 安装docker和docker-compose

一、环境

系统:alma8.5(Centos8.5)
docker版本:20.10.12
docker-compose版本:2.2.2

二、互联网环境

  • 点我跳转至无互联网环境

2.1 环境配置

# 修改镜像源
sed -e 's|^mirrorlist=|#mirrorlist=|g' -e 's|^# baseurl=https://repo.almalinux.org|baseurl=https://mirrors.aliyun.com|g' -i.bak  /etc/yum.repos.d/almalinux*.repo
# 更新镜像源
dnf makecache
# 安装NTP 
dnf install chrony
# 修改chrony配置文件指定NTP源为阿里NTP
sed -r -i 's?^pool.+iburst?pool ntp.aliyun.com iburst?' /etc/chrony.conf
# 重启chrony服务
systemctl restart chronyd
# 开机自动启动chrony服务
systemctl enable chronyd
# 查看时间服务器状态
chronyc sources -v
# 创建docker目录
mkdir -p /etc/docker /opt/docker
# 创建docker配置文件
tee /etc/docker/daemon.json <<-'EOF'
{
	"data-root": "/opt/docker",
	"log-driver": "json-file",
	"log-opts": {
		"max-size": "800m",
		"max-file": "50"
	},
	"registry-mirrors": [
		"https://hub-mirror.c.163.com",
		"https://docker.mirrors.ustc.edu.cn",
		"https://registry.docker-cn.com"
	]
}
EOF

2.2 安装docker

# 安装镜像源配置工具
dnf install -y yum-utils
# 添加软件源
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
# 安装docker
# 离线安装用户可以在这里执行dnf download --resolve docker-ce docker-ce-cli containerd.io下载所有包
dnf install docker-ce docker-ce-cli containerd.io
# 启动docker
systemctl start docker
# docker开机自动启动
systemctl enable docker
# containerd容器开机自动启动
systemctl enable containerd
# 查看docker版本信息
docker info
# 下载docker-compose
curl -L "https://github.com/docker/compose/releases/download/v2.2.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
# 给予docker-compose执行权
chmod +x /usr/local/bin/docker-compose
# 查看docker-compose版本信息
docker-compose --version

三、无互联网环境

  • 点我跳转至互联网环境

离线文件包docker-20.10.12-centos8-offline.tar.gz

  • containerd.io-1.4.12-3.1.el8.x86_64.rpm
  • docker-ce-20.10.12-3.el8.x86_64.rpm
  • docker-ce-cli-20.10.12-3.el8.x86_64.rpm
  • docker-ce-rootless-extras-20.10.12-3.el8.x86_64.rpm
  • docker-scan-plugin-0.12.0-3.el8.x86_64.rpm
  • 阿里Docker镜像源下载以上包:https://mirrors.aliyun.com/docker-ce/linux/centos/8/x86_64/stable/Packages/
  • checkpolicy-2.9-1.el8.x86_64.rpm
  • fuse-common-3.2.1-12.el8.x86_64.rpm
  • fuse3-3.2.1-12.el8.x86_64.rpm
  • fuse3-libs-3.2.1-12.el8.x86_64.rpm
  • libcgroup-0.41-19.el8.x86_64.rpm
  • policycoreutils-python-utils-2.9-16.el8.noarch.rpm
  • python3-audit-3.0-0.17.20191104git1c2f876.el8.x86_64.rpm
  • python3-libsemanage-2.9-6.el8.x86_64.rpm
  • python3-policycoreutils-2.9-16.el8.noarch.rpm
  • python3-setools-4.3.0-2.el8.x86_64.rpm
  • tar-1.30-5.el8.x86_64.rpm
  • 阿里alma镜像源下载以上包:https://mirrors.aliyun.com/almalinux/8.5/BaseOS/x86_64/os/Packages/
  • 阿里centos镜像源:https://mirrors.aliyun.com/centos/8.5.2111/BaseOS/x86_64/os/Packages/
  • container-selinux-2.167.0-1.module_el8.5.0+2586+018f24d7.noarch.rpm
  • fuse-overlayfs-1.7.1-1.module_el8.5.0+2586+018f24d7.x86_64.rpm
  • libslirp-4.4.0-1.module_el8.5.0+2586+018f24d7.x86_64.rpm
  • slirp4netns-1.1.8-1.module_el8.5.0+2586+018f24d7.x86_64.rpm
  • 阿里alma镜像源下载以上包:https://mirrors.aliyun.com/almalinux/8.5/AppStream/x86_64/os/Packages/
  • 阿里centos镜像源:https://mirrors.aliyun.com/centos/8.5.2111/AppStream/x86_64/os/Packages/
  • docker-compose-linux-x86_64:https://github.com/docker/compose/releases/download/v2.2.2/docker-compose-Linux-x86_64

3.1 环境配置

# 创建docker目录
mkdir -p /etc/docker /opt/docker
# 创建docker配置文件
tee /etc/docker/daemon.json <<-'EOF'
{
	"graph": "/opt/docker",
	"log-driver": "json-file",
	"log-opts": {
		"max-size": "800m",
		"max-file": "50"
	}
}
EOF

3.2 安装docker和docker-compose

# 进入opt目录
cd /opt
# 上传离线文件包docker-20.10.12-centos8-offline.tar.gz至/opt目录
# 解压
tar -zxvf docker-20.10.12-centos8-offline.tar.gz
# 进入目录
cd /opt/docker-20.10.12-centos8-offline
# 安装docker
rpm -ivh *.rpm
# 复制docker-compose二进制文件至bin目录
cp /opt/docker-20.10.12-centos8-offline/docker-compose-linux-x86_64 /usr/local/bin/docker-compose
# 给予执行权限
chmod +x /usr/local/bin/docker-compose
# 启动docker
systemctl start docker
# docker开机自动启动
systemctl enable docker
# containerd容器开机自动启动
systemctl enable containerd
# 查看docker版本信息
docker info
# 查看docker-compose版本信息
docker-compose --version

你可能感兴趣的:(Centos,docker,Zabbix,docker,容器,运维)