Home > Operation and Maintenance > Docker > Offline installation of docker fails to start

Offline installation of docker fails to start

PHPz
Release: 2023-04-25 09:38:04
Original
1541 people have browsed it

Under the current wave of cloud computing and containerization, Docker has emerged as a mainstream application containerization technology and has become one of the most widely used tools in the field of operation, maintenance and development. In this context, Docker offline installation has also become a very common requirement. Because many users cannot connect to the Internet, or Internet connections are prohibited due to security and other factors, offline installation has become one of the most convenient installation methods. However, during the offline installation of Docker, the installation is often successful but the startup fails, which is a very troublesome problem for beginners.

This article will start from the actual operation, introduce the Docker offline installation method, and conduct a detailed analysis of the startup failure to provide you with a detailed guide.

1. Docker offline installation

There are two ways to install Docker offline: one is to install by downloading the Docker binary file, and the other is to install by configuring the yum source. The former is mainly suitable for servers without network conditions, while the latter is suitable for offline installation of Linux development environments.

1. Install by downloading the Docker binary file

The principle of this method is relatively simple, that is, download the Docker binary file to the local and then install it. The specific steps are as follows:

1.1 Obtain the Docker binary file

Download the corresponding version of the Docker binary file from the official website https://www.docker.com/. When downloading, you need to know the information about the current operating system. For centos system, you can choose to download the binary file corresponding to the following address.

https://download.docker.com/linux/static/stable/x86_64/ docker-version number.tgz

1.2 Install Docker binary file

When installing You need to unzip the downloaded binary file and move the docker and dockerd files to the /usr/bin directory.

tar -xvf docker-version number.tgz
cp docker/* /usr/bin

2. Install by configuring the yum source

Under the centos system , you can install Docker offline by configuring the yum source. The specific steps are as follows:

2.1 Obtain the yum source of Docker

Download the corresponding version of the Docker installation package from the official website https://www.docker.com/. When downloading, you need to know the information about the current operating system and download the rpm package corresponding to the system version.

2.2 Create a new local yum source

Create a local yum source directory, copy the downloaded Docker installation package to this directory, and create the directory through the createrepo command

mkdir /var/docker
cp docker-ce*.rpm /var/docker
createrepo /var/docker

2.3 Configure yum source

in /etc/yum Create a new repo file in the .repos.d directory and write the following content

[docker-local]
name=Docker Local repo
baseurl=file:///var/docker
enabled=1
gpgcheck=0

2.4 Install Docker

Execute the following command to install Docker

yum install docker-ce

二, Solution to startup failure

1. Problem description

After completing the above offline installation of Docker, you may encounter Docker startup failure and the following error occurs:

$ sudo systemctl start docker
Job for docker.service failed because the control process exited with error code.
See "systemctl status docker.service" and "journalctl -xe" for details.

Executing the systemctl status docker.service command shows that the reason for the startup failure is that the "ExecStart" command in the docker.service file cannot be executed successfully:

$ sudo systemctl status docker.service
...
Apr 30 07:40:32 localhost.localdomain systemd[1]: Started Docker Application Container Engine.
Apr 30 07:40:32 localhost.localdomain systemd[1]: docker.service: main process exited, code=exited , status=1/FAILURE
Apr 30 07:40:32 localhost.localdomain systemd[1]: Unit docker.service entered failed state.
Apr 30 07:40:32 localhost.localdomain systemd[1]: docker.service failed.
Apr 30 07:40:32 localhost.localdomain systemd[1]: docker.service holdoff time over, scheduling restart.
Apr 30 07:40:32 localhost.localdomain systemd[1] : Stopped Docker Application Container Engine.

$sudo journalctl -xe
dockerd-current[14552]: time="2020-04-30T07:40:32.652790118 08:00" level=error msg=" systemd notifier failed: Unable to load systemd module \"libsystemd.so\": cannot open shared o
dockerd-current[14552]: failed to start daemon: Error initializing network controller: list bridge addresses failed: PredefinedLocalScopeDefaultNetworks List failed: Predefined
dockerd-current[14552]: Error starting daemon: Error initializing network controller: list bridge addresses failed: PredefinedLocalScopeDefaultNetworks List failed: Predefined
systemd[1]: docker.service: main process exited, code=exited, status=1/FAILURE
systemd[1]: Failed to start Docker Application Container Engine.
systemd[1]: Unit docker.service entered failed state.
systemd[1]: docker.service failed.

2. Problem analysis

Through the above error message, you can find that the reason why Docker failed to start is because Docker's network controller cannot be started. Specifically, this is because Docker's network controller manages the container network through the iptables firewall, and the firewall prohibits all non-local traffic by default. For Docker, relevant rules will be automatically added to iptables when it is started for the first time. However, if Docker installed offline is started for the first time, the addition of rules will fail, causing the network controller to fail to start. The specific manifestation is that when the user starts Docker, Docker will automatically create a bridge named docker0 based on the local IP address. If this operation fails, Docker will not be able to start.

3. Problem solving

There are two main ways to solve this problem:

3.1 Create docker0 bridge

Manually creating docker0 bridge can solve the problem For this problem, under centos, you can execute the following command to manually create the docker0 bridge:

sudo ip link add name docker0 type bridge
sudo ip addr add dev docker0 172.17.0.1/16
sudo ip link set dev docker0 up

After completing the above operations, start Docker again and execute the following command as an administrator:

$ sudo systemctl start docker

to complete Docker of startup.

3.2 Modify the firewall rules

Turning off the firewall or modifying the firewall rules is also an effective way to solve this problem. When turning off the firewall, you can use the following command:

$ systemctl stop firewalld
$ systemctl disable firewalld

But this situation is not recommended. It is recommended to keep the system's firewall as much as possible according to security requirements. .

If you want to modify the iptables rules, you can add the rules through the following command:

$ sudo iptables -P FORWARD ACCEPT
$ sudo iptables -I FORWARD -j ACCEPT
$ sudo service iptables save

After performing the above operations, start Docker again and it will start normally.

3. Summary

Through the introduction of this article, we can see that when installing Docker offline, Docker may not start due to network problems. At this time, we need to understand the working principle of Docker's network controller and manually configure it or make certain modifications to the iptables firewall to finally solve the problem of Docker startup failure. Of course, we can also solve such problems by checking specific error messages in time and conducting analysis.

Therefore, during the offline installation and startup of Docker, we need to remain cautious and patient, continue to experiment and debug, and finally find a suitable method to solve the problem.

The above is the detailed content of Offline installation of docker fails to start. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template