Docker离线安装部署文档

Docker离线安装部署文档

文档基于centos 7.5; docker 19.03.5

1. 准备linux环境

1.1 先关闭防火墙** sudo systemctl stop firewalld

image.png

1.2 关闭selinux策略; vi /etc/selinux/config ; 修改完成后,重启一次系统;可以使用reboot

image.png

1.3 检查文件。 检查是否存在/etc/timezone 文件,如果没有,在后面执行docker run 命令的时候,需要删除命令中关于/etc/timezone 的映射,以免报错,只使用/etc/localtime 做时间同步。

image.png

准备工作完成。

2. 安装docker

如果没有安装包,在官网下载二进制安装包,下载地址https://download.docker.com/linux/static/stable/x86_64/

image.png

下面只需要安官网的步骤执行就可以了,官网安装网址https://docs.docker.com/engine/install/binaries/;

就下面这三步:

2.1 解压:tar xzvf docker-19.03.5.tgz

2.2 拷贝: sudo cp docker/* /usr/bin/

2.3 运行: sudo dockerd &。

这一步可以不用后台执行,即直接执行sudo dockerd,命令行界面会直接打印执行结果,查看执行结果。

image.png
image.png

如果没有异常,按 ctrl + c 强制退出,Docker 其实已经安装好了,后面会配置开机启动。

官网教程到此结束。

3. 配置docker 开机启动

这里包括两个文件(强调一下必须先执行1.2步骤,即关闭selinux,并且重启了系统)

image.png

docker.service :

[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

docker.socket:

[Unit]

Description=Docker Socket for the API

PartOf=docker.service

[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

执行下列命令,设置docker开机自启;在docker.service, docker.socket所在的文件夹中执行下命令,设置docker开机自启。

sudo cp docker.socket /etc/systemd/system

sudo cp docker.service /etc/systemd/system

sudo systemctl daemon-reload

sudo systemctl start docker

sudo systemctl enable docker

重启一下系统,检验docker是否开机自启

 sudo reboot

重启成功后,执行docker ps 检验docker是否启动成功。

到这里docker已经安装完成,并且开机自启。

你可能感兴趣的:(Docker离线安装部署文档)