Home>Article>Operation and Maintenance> What to do if the docker port is blocked

What to do if the docker port is blocked

藏色散人
藏色散人 Original
2021-12-31 11:21:29 6757browse

Solution to docker port failure: 1. Open the command window; 2. Execute "sysctl -w net.ipv4.ip_forward=1 sed -i "/net.ipv4.ip_forward/ s/0/1/ g"/etc/sysctl.conf" command.

What to do if the docker port is blocked

The operating environment of this tutorial: ubuntu 16.04 system, Docker version 20.10.11, Dell G3 computer.

What should I do if the docker port is blocked?

Docker: The port of a normally running container suddenly becomes blocked. General check methods:

## Premise: Under normal circumstances, in the DOCKER environment we run, there may be problems with container ports being blocked. Here are some notes I have experienced and summarized to help check the problem.


1. The iptables rules have been modified:

If this is the reason, we can restart docker to make the iptables forwarding rules take effect again, which can generally be solved


2. The system parameters are modified (the parameter net.ipv4.ip_forward is changed to 0):

The default value of this kernel parameter in the Linux system is 0. When we install docker, it will be Docker changed it to 1, and then implemented port forwarding, and the container ran normally

However, docker only changed the memory and did not take effect in the configuration file, so the configuration file still has 0 as follows:

sysctl -a |grep "ipv4.ip_forward" =====> net.ipv4.ip_forward = 1 cat /etc/sysctl.conf| grep "ipv4.ip_forward" =====> net.ipv4.ip_forward = 0

This kind of In this case, if someone changes other parameters and then takes effect through sysctl -p, then the parameter changed by docker will be reconfigured to be consistent with the one in the /etc/sysctl.conf file

, causing the port to be blocked. This Sometimes you need to restart docker to change it to 1 again.

So when we install docker, we need to set this parameter to 1 first. The command to install docker is as follows:

sysctl -w net.ipv4.ip_forward=1 sed -i "/net.ipv4.ip_forward/ s/0/1/g" /etc/sysctl.conf

Summary

In fact, all that is said is to restart iptables and restart docker. , you can solve the basic problem, haha, I talked some nonsense, but I hope I can share it with everyone

Recommended learning: "

docker video tutorial"

The above is the detailed content of What to do if the docker port is blocked. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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