centos离线环境下安装docker和docker-compose

下载软件包

本次安装下载的软件包版本:

  • docker-19.03.9.tgz
  • docker-compose 1.24.1

关闭防火墙

本次安装使用centos7.5操作系统.

# 关闭防火墙
systemctl stop firewalld
systemctl disable firewalld
# 查看防火墙状态
systemctl status firewalld

# 关闭selinux
setenforce 0
vim /etc/selinux/config
# 查看selinux状态
/usr/sbin/sestatus -v

安装docker

  • 准备docker.servicedocker服务化配置文件
[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
  • 依次执行命令安装
# 解压tar包
tar -xvf docker-19.03.9.tgz
# 将docker目录移到/usr/bin目录下
cp docker/* /usr/bin/
# 将docker.service 移到/etc/systemd/system/ 目录
cp docker.service /etc/systemd/system/
# 添加文件权限
chmod +x /etc/systemd/system/docker.service
# 重新加载配置文件
systemctl daemon-reload
# 启动docker
systemctl start docker
# 设置开机自启
systemctl enable docker.service
# 验证docker安装是否成功
docker -v

安装docker-compose

# 添加文件权限
chmod +x /xxx/docker-compose
# 创建软链接
ln -s /xxx/docker-compose /usr/bin/docker-compose
# 验证安装是否成功
docker-compose --version

配置普通用户可以使用docker命令

# 创建用户组,默认安装docker可能已经创建了
sudo groupadd docker
# 示例
sudo usermod -aG docker testuser
# 重新服务再登录即可使用docker命令
sudo systemctl restart docker

猜你喜欢

转载自blog.csdn.net/wzy_168/article/details/115115430