Install docker offline in linux system (step-by-step & one-click method)

1 Introduction

In some project scenarios, the server is not allowed to connect to the external network. At this time, if you want to install and deploy the docker container on the server, you cannot use the online method, but you can use the offline method for installation. Let's take a look at the two methods of offline installation.

One is a step-by-step installation method, and the other is a one-click installation method.

2 Installation preparation

First, download the docker offline installation package on another computer with external network access. The download address is as follows:

Index of linux/static/stable/x86_64/

Here we choose the stable community version docker-18.06.3-ce.tgz.

After downloading, use WinSCP and other tools to upload the file docker-18.06.3-ce.tgz to a Linux system server that cannot be accessed from the Internet. Here, the Centos7.9 system is used as an example.

3 step-by-step installation method

3.1 Decompression

tar -zxvf docker-18.06.3-ce.tgz

The files in the unzipped folder docker are as follows:

3.2 Copy files

Copy all the files in docker to /usr/bin using the following command

cp ./docker/* /usr/bin

3.3 Create docker.service file

cd /etc/systemd/system/
touch docker.service

3.4 Edit the docker.service file

First open docker.service

vim docker.service

Then copy the following content to docker.service.

Note, change the ip address in it to your server address, and other parameters do not need to be changed.

--insecure-registry=192.168.205.230

[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 --selinux-enabled=false --insecure-registry=192.168.205.230
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

 After editing, press the ESC key à:wq to save and exit the docker.service file.

3.5 Add executable permissions

chmod +x docker.service

3.6 Load docker.service

systemctl daemon-reload

Note that if the docker.service file is modified, the file needs to be reloaded.

3.7 start docker

systemctl start docker

3.8 view docker

systemctl status docker

docker -v

 

3.9 Set up auto-start

systemctl enable docker.service

In this way, every time the system starts, docker will automatically start randomly.

4 One-key installation method

If you think the above steps are cumbersome, you can also use the following method to install docker with one click.

4.1 Make docker.service file

In the same directory as docker-18.06.3-ce.tgz, create docker.service, open and edit the file, the content of the file is exactly the same as that in Section 3.4, and will not be repeated here.

4.2 Make a one-click installation script

touch install.sh

Open and edit install.sh, copy the following content to install.sh, save and exit.

#!/bin/sh

echo '解压tar包'
tar -xvf $1
echo '将docker目录下所有文件复制到/usr/bin目录'
cp docker/* /usr/bin
echo '将docker.service 复制到/etc/systemd/system/目录'
cp docker.service /etc/systemd/system/
echo '添加文件可执行权限'
chmod +x /etc/systemd/system/docker.service
echo '重新加载配置文件'
systemctl daemon-reload
echo '启动docker'
systemctl start docker
echo '设置开机自启'
systemctl enable docker.service
echo 'docker安装成功'
docker -v

4.3 Make a one-click uninstall script

Touch uninstall.sh, copy the following content to uninstall.sh, save and exit.

#!/bin/sh

echo '停止docker'
systemctl stop docker
echo '删除docker.service'
rm -f /etc/systemd/system/docker.service
echo '删除docker文件'
rm -rf /usr/bin/docker*
echo '重新加载配置文件'
systemctl daemon-reload
echo '卸载成功'

4.4 install docker

At this time, under the same directory as docker-18.06.3-ce.tgz, there are three files: docker.service, install.sh, and uninstall.sh created above:

Give executable permissions to install.sh and uninstall.sh respectively.

chmod +x install.sh
chmod +x uninstall.sh

 start installation

sh install.sh docker-18.06.3-ce.tgz

View docker status

 

5 summary

The one-click installation method actually writes the steps of the step-by-step installation method into a shell script. The process is essentially the same. The advantage is that it saves time and is less prone to errors when installing on a new machine. If you want to uninstall docker, one-click operation is also very convenient.

6 Reference

Install docker on centos7-linux (offline mode) - Qingyang Xianyun - Blog Garden

The process of installing docker offline in Linux (one-click installation) - Programmer Sought

Guess you like

Origin blog.csdn.net/chexlong/article/details/127932711