yzgblogs

华为鲲鹏麒麟安装docker

安装 Docker-ce

下载二进制docker

官网下载地址:https://download.docker.com/linux/static/stable/aarch64/

解压下载好的压缩包

tar -zxvf docker-20.10.9.tgz

移动解压出来的二进制文件到 /usr/bin 目录中

mv docker/* /usr/bin/

测试启动

dockerd

添加 systemd

添加 docker 的 systemd 服务脚本至 /usr/lib/systemd/system/

脚本参考自 https://github.com/docker/docker-ce

cat > /usr/lib/systemd/system/docker.service <<\'EOF\'
[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network-online.target docker.socket firewalld.service containerd.service
Wants=network-online.target containerd.service
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 -H fd:// --containerd=/run/containerd/containerd.sock
ExecReload=/bin/kill -s HUP $MAINPID
TimeoutStartSec=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
# 使用这个才能启动成功
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
Wants=network-online.target

[Service]
Type=notify
EnvironmentFile=-/etc/sysconfig/docker
EnvironmentFile=-/etc/sysconfig/docker-storage
EnvironmentFile=-/etc/sysconfig/docker-network
Environment=GOTRACEBACK=crash

ExecStart=/usr/bin/dockerd $OPTIONS \
                           $DOCKER_STORAGE_OPTIONS \
                           $DOCKER_NETWORK_OPTIONS \
                           $INSECURE_REGISTRY
ExecReload=/bin/kill -s HUP $MAINPID
LimitNOFILE=1048576
LimitNPROC=1048576
LimitCORE=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

[Install]
WantedBy=multi-user.target
EOF
#============================================
cat > /etc/sysconfig/docker <<\'EOF\'
# /etc/sysconfig/docker

# Modify these options if you want to change the way the docker daemon runs
OPTIONS=\'--live-restore\'

DOCKER_CERT_PATH=/etc/docker

# If you have a registry secured with https but do not have proper certs
# distributed, you can tell docker to not look for full authorization by
# adding the registry to the INSECURE_REGISTRY line and uncommenting it.
# INSECURE_REGISTRY=\'--insecure-registry\'

# Location used for temporary files, such as those created by
# docker load and build operations. Default is /var/lib/docker/tmp
# Can be overridden by setting the following environment variable.
# DOCKER_TMPDIR=/var/tmp
EOF
#========================================================

cat > /etc/sysconfig/docker-storage <<\'EOF\'
# This file may be automatically generated by an installation program.

# By default, Docker uses a loopback-mounted sparse file in
# /var/lib/docker.  The loopback makes it slower, and there are some
# restrictive defaults, such as 100GB max storage.

# If your installation did not set a custom storage for Docker, you
# may do it below.

# Example: Use a custom pair of raw logical volumes (one for metadata,
# one for data).
# DOCKER_STORAGE_OPTIONS = --storage-opt dm.metadatadev=/dev/mylogvol/my-docker-metadata --storage-opt dm.datadev=/dev/mylogvol/my-docker-data

DOCKER_STORAGE_OPTIONS=
EOF
#======================================================

cat > /etc/sysconfig/docker-network <<\'EOF\'
# /etc/sysconfig/docker-network
DOCKER_NETWORK_OPTIONS=
EOF

下面的不需要,在鲲鹏麒麟系统走不通

################################

根据 docker.serviceUnit.After 需求添加 docker.socket 脚本至 /usr/lib/systemd/system/

脚本参考自 https://github.com/docker/docker-ce

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

[Socket]
# If /var/run is not implemented as a symlink to /run, you may need to
# specify ListenStream=/var/run/docker.sock instead.
ListenStream=/run/docker.sock
SocketMode=0660
SocketUser=root
SocketGroup=docker

[Install]
WantedBy=sockets.target
EOF

如果缺少该文件,启动 docker 时会报如下错误:

systemctl start docker
Failed to start docker.service: Unit docker.socket not found.

根据 docker.serviceUnit.After 需求添加 containerd.service 脚本至 /usr/lib/systemd/system/

脚本参考自 https://github.com/containerd/containerd

cat > /usr/lib/systemd/system/containerd.service <<\'EOF\'
[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=infinity
# 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

注意:如果缺少该文件,启动 docker 时会报如下错误:

systemctl restart docker
Failed to restart docker.service: Unit containerd.service not found.

##################################

重载 systemd 配置文件

systemctl daemon-reload

创建 docker 组

groupadd docker

如不创建 docker 组在通过 systemctl 启动时会报错如下

Dependency failed for Docker Application Container Engine.
Job docker.service/start failed with result \'dependency\'.

启动 docker 服务

systemctl start docker
systemctl enable docker

修改 docker 配置文件并查看安装好的 docker 基本信息

mkdir -p /etc/docker/
cat > /etc/docker/daemon.json <<\'EOF\'
{
"registry-mirrors": ["https://xxxxxxxxxxxxxxxxxxxxxx.mirror.swr.myhuaweicloud.com"]
}
EOF

重启 docker 服务

systemctl restart docker

查看 docker info

docker info

参考:https://kev1nchan.vercel.app/posts/6da98871/

分类:

技术点:

相关文章:

  • 2022-12-23
  • 2021-12-01
  • 2021-10-22
  • 2021-12-02
  • 2021-12-12
  • 2021-11-13
猜你喜欢
  • 2021-12-21
  • 2021-12-31
  • 2021-08-25
  • 2021-07-31
  • 2021-05-22
  • 2022-02-17
  • 2021-12-31
相关资源
相似解决方案