CentOS7.9安装docker-20.10.7

1 环境

操作系统:CentOS7.9

2 下载安装包

cd /home
mkdir tool
cd tool
curl -o docker-20.10.7.tgz https://download.docker.com/linux/static/stable/x86_64/docker-20.10.7.tgz

3 解压安装包

cd /home/tool
tar zxvf docker-20.10.7.tgz
mv docker/* /usr/bin/

4 增加用户

groupadd docker
usermod -aG docker $USER
newgrp docker

5 system管理containerd

5.1 containerd.service

cat > /usr/lib/systemd/system/containerd.service << EOF
# Copyright The containerd Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

[Unit]
Description=containerd container runtime
Documentation=https://containerd.io
After=network.target local-fs.target

[Service]
ExecStartPre=-/sbin/modprobe overlay
ExecStart=/usr/bin/containerd

Type=notify
Delegate=yes
KillMode=process
Restart=always
RestartSec=5
# Having non-zero Limit*s causes performance problems due to accounting overhead
# in the kernel. We recommend using cgroups to do container-local accounting.
LimitNPROC=infinity
LimitCORE=infinity
LimitNOFILE=1048576
# Comment TasksMax if your systemd version does not supports it.
# Only systemd 226 and above support this version.
TasksMax=infinity
OOMScoreAdjust=-999

[Install]
WantedBy=multi-user.target
EOF

5.2 启动并设置开机启动

# 加载服务配置
systemctl daemon-reload
# 设置开机启动
systemctl enable containerd
# 启动
systemctl start containerd
# 查看错误命令
journalctl -xe

6 systemd管理docker

6.1 docker.service

cat > /usr/lib/systemd/system/docker.service << EOF
[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network-online.target firewalld.service containerd.service
Wants=network-online.target
Requires=docker.socket

[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
TimeoutSec=0
RestartSec=2
Restart=always

# Note that StartLimit* options were moved from "Service" to "Unit" in systemd 229.
# Both the old, and new location are accepted by systemd 229 and up, so using the old location
# to make them work for either version of systemd.
StartLimitBurst=3

# Note that StartLimitInterval was renamed to StartLimitIntervalSec in systemd 230.
# Both the old, and new name are accepted by systemd 230 and up, so using the old name to make
# this option work for either version of systemd.
StartLimitInterval=60s

# 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

# Comment TasksMax if your systemd version does not support it.
# Only systemd 226 and above support this option.
TasksMax=infinity

# 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
OOMScoreAdjust=-500

[Install]
WantedBy=multi-user.target
EOF

6.2 docker.socket

cat > /usr/lib/systemd/system/docker.socket << EOF
[Unit]
Description=Docker Socket for the API

[Socket]
ListenStream=/var/run/docker.sock
SocketMode=0660
SocketUser=root
SocketGroup=docker

[Install]
WantedBy=sockets.target

EOF

说明:如果不增加该文件,执行systemctl enable docker命令时,报错:Failed to execute operation: Bad message

以以文件配置在docker组的用户也有权限管理docker。

6.3 daemon.json

mkdir /etc/docker
## data-root 指定docker数据存储根目录
cat > /etc/docker/daemon.json << EOF
{
  "registry-mirrors": ["https://pee6w651.mirror.aliyuncs.com","https://registry.docker-cn.com","http://hub-mirror.c.163.com","https://docker.mirrors.ustc.edu.cn"],
  "data-root": "/usr/docker/data" 
}
EOF

6.4 启动并设置开机启动

systemctl daemon-reload
systemctl enable docker
systemctl start docker
systemctl status docker
# 查看错误命令
journalctl -xe

7 验证Docker

docker

8 安装docker-compose-1.25.0

curl -L https://github.com/docker/compose/releases/download/1.25.0/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose

9 FAQ

1. Docker拉取镜像报错:Error response from daemon: Get https://registry-1.docker.io/v2/: dial tcp: lookup registry-1.docker

解决方案:在cat /etc/sysconfig/network-scripts/ifcfg-enp0s3中增加DNS配置,“ifcfg-enp0s3”为实际的网卡。

 腾讯 DNS
IP: 119.29.29.29 182.254.116.116

阿里DNS
IP:223.5.5.5 223.6.6.6

百度DNS
IP:180.76.76.76

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值