centos7.9离线安装docker

复制代码
#docker 官方下载地址
https://download.docker.com/linux/static/stable/
#进入网站后根据自己服务器架构选择对应安装包下载

#解压安装包
[qds@kubernetes ~]$ tar -zxvf docker-23.0.3.tgz 
docker/
docker/docker-proxy
docker/containerd-shim-runc-v2
docker/ctr
docker/docker
docker/docker-init
docker/runc
docker/dockerd
docker/containerd
[qds@kubernetes ~]$ 

#拷贝安装包到系统路径下
[qds@kubernetes ~]$ sudo cp -r docker/* /usr/bin/

dockerd 启动

应用生产环境极不推荐,测试环境无所谓。

复制代码
dockerd &

systemctl 管理docker需要编写三个配置文件,粘贴下列配置信息即可。

  • docker.service
  • docker.socket
  • containerd.service
配置信息

/usr/lib/systemd/system/docker.service

Unit

Description=Docker Application Container Engine

Documentation=https://docs.docker.com

After=network-online.target docker.socket firewalld.service containerd.service time-set.target

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 --data-root /docker/data

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

/usr/lib/systemd/system/docker.socket

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=/var/run/docker.sock

SocketMode=0660

SocketUser=root

SocketGroup=docker

Install

WantedBy=sockets.target

/usr/lib/systemd/system/containerd.service

/usr/lib/systemd/system/containerd.service

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=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

重新加载systemctl配置文件

复制代码
[qds@kubernetes ~]$ sudo systemctl daemon-reload
创建docker用户组
复制代码
[qds@kubernetes ~]$ sudo groupadd docker 
将操作用户添加到docker组
复制代码
[qds@kubernetes ~]$ sudo usermod -aG docker qds
知识扩展

-a|--append :把用户追加到某些组中,仅与-G选项一起使用。

-G|--groups:修改用户的附加组,会覆盖之前的附加组。

-g|--gid:修改用户的主组(pid)

配置自启动、启动服务
复制代码
[qds@kubernetes ~]$ sudo systemctl enable docker
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.
[qds@kubernetes ~]$ sudo systemctl enable containerd
Created symlink from /etc/systemd/system/multi-user.target.wants/containerd.service to /usr/lib/systemd/system/containerd.service.
[qds@kubernetes ~]$ sudo systemctl start docker
打印docker版本验证服务状态 (示例)
复制代码
[qds@kubernetes ~]$ docker version
Client:
 Version:           23.0.3
 API version:       1.42
 Go version:        go1.19.7
 Git commit:        3e7cbfd
 Built:             Tue Apr  4 22:02:08 2023
 OS/Arch:           linux/amd64
 Context:           default

Server: Docker Engine - Community
 Engine:
  Version:          23.0.3
  API version:      1.42 (minimum version 1.12)
  Go version:       go1.19.7
  Git commit:       59118bf
  Built:            Tue Apr  4 22:05:02 2023
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          v1.6.20
  GitCommit:        2806fc1057397dbaeefbea0e4e17bddfbd388f38
 runc:
  Version:          1.1.5
  GitCommit:        v1.1.5-0-gf19387a
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad
相关推荐
IT成长日记1 小时前
【Docker基础】Docker数据持久化与卷(Volume)介绍
运维·docker·容器·数据持久化·volume·
热爱生活的猴子2 小时前
阿里云服务器正确配置 Docker 国内镜像的方法
服务器·阿里云·docker
物联网老王4 小时前
Ubuntu Linux Cursor 安装与使用一
linux·运维·ubuntu
艾伦_耶格宇5 小时前
【ACP】阿里云云计算高级运维工程师--ACP
运维·阿里云·云计算
FrankYoou6 小时前
Jenkins 与 GitLab CI/CD 的核心对比
java·docker
一位摩羯座DBA6 小时前
Redhat&Centos挂载镜像
linux·运维·centos
隆里卡那唔6 小时前
在dify中通过http请求neo4j时为什么需要将localhost变为host.docker.internal
http·docker·neo4j
疯子的模样6 小时前
Docker 安装 Neo4j 保姆级教程
docker·容器·neo4j
cui_win7 小时前
【网络】Linux 内核优化实战 - net.core.flow_limit_table_len
linux·运维·网络
风清再凯7 小时前
自动化工具ansible,以及playbook剧本
运维·自动化·ansible