Linux离线安装Docker

Docker引擎离线安装及集群配置

1. 下载对应二进制包

根据不同操作系统架构选择,例如:

Linux CentOS7选择:x86_64
https://download.docker.com/linux/static/stable/

2. 解压

tar xzvf docker-19.03.4.tgz

3. 将解压后的目录复制到/usr/bin下

cp docker/* /usr/bin

4. 添加docker.service文件

vi /etc/systemd/system/docker.service

[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network-online.target docker.socket firewalld.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 -H fd://
ExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:2375 -H unix://var/run/docker.sock
ExecReload=/bin/kill -s HUP $MAINPID
LimitNOFILE=1048576
# 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
# 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

5. 执行

chmod +x /etc/systemd/system/docker.service

6. 添加 docker.socket 文件

vi /lib/systemd/system/docker.socket

[Unit]
Description=Docker Socket for the API
PartOf=docker.service

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

[Install]
WantedBy=sockets.target

7. 添加daemon.json文件

vi /etc/docker/daemon.json

{
     
  "registry-mirrors": ["https://registry.docker-cn.com"],
  "insecure-registries": ["xxx.xxx.xxx.xxx:5000"],
  "data-root": "/data/docker"
}

8. 启动docker服务并设置开机自启

systemctl daemon-reload
systemctl start docker
systemctl enable docker.service

至此docker安装完毕,文章最后附有两个常见错误处理方法,希望对大家有帮助,以下是配置集群方法

初始化集群:docker swarm init

在主节点服务器执行命令:docker swarm init,保存控制台输出的以下命令:

docker swarm join --token SWMTKN-1-1utny8u213o4varez63ptxru7iou5d8jzzimfehyxhk08yqqfk-65f4593hpdczbi70a58comcfv xxx.xxx.xxx.xxx:2377

在需要其他装有docker的服务器上运行以上命令即可加入集群

错误处理

A dependency job for docker.service failed. See 'journalctl -xe' for details.

处理方法:给系统添加一个docker组:

groupadd docker
chattr -i /etc/group
systemctl enable docker && systemctl start docker

docker: Error response from daemon: OCI runtime create failed: container_linux.go:349: starting container process caused "process_linux.go:449: container init caused \"write /proc/self/attr/keycreate: permission denied\"": unknown.

处理方法:

修改 /etc/selinux/config中SELINUX=disabled

你可能感兴趣的:(docker,docker,linux,swarm)