Solutions to the problem that docker cannot ping the host: 1. Modify daemon.json; 2. Turn off the firewall; 3. Modify sysctl.conf; 4. Reset the network bridge.
The operating environment of this article: ubuntu16.04 system, Docker 20.10.11, Dell G3 computer.
What should I do if docker cannot ping the host?
Docker bridge mode cannot ping the host
Problem description:
Docker
The network mode is divided into four types. Generally, when we do not set it, the default is bridge
single bridge mode, the container uses an independent network Namespace
and is connected to the docker0
virtual network card. Communicate with the host through the docker0
bridge and Iptables nat
table configuration.
? At this time, test on the bastion machine and use busybox
to test:
#?拉取鏡像 docker?pull?busybox #?運(yùn)行容器 docker?run?-itd?--name?busy_bridge?busybox
? Instruction docker network inspect bridge
Check the network:
ip. You can see that
ip has been allocated, but
ping fails when pinging the external network and cannot Connect to the external network:
docker, and then they can connect. Usually it is because a certain configuration is modified and then Restarting works, it has no effect here. Generally, there are several types of modifications. Try them one by one below:
- Modifydaemon.json
daemon.json to specify the allocation. Use the command
vim /etc/docker/daemon.jsonAdd after entering:
{"bip":"172.16.10.1/24"}? Although you can access it by restarting
docker and creating a container, there is no conflict at all between the
ip assigned by the original bastion host and the container. The method doesn’t work.
- Turn off the firewall
docker, the container could be accessed normally.
?However, the firewall on the bastion machine is originally turned off, so this method is useless.
- Modifysysctl.conf
The internal network of the host is normal, and the network with other hosts is normal. The connection fails. Other hosts cannot connect to the port mapped on the docker
host, and docker
cannot connect to external hosts internally. Use the docker info
command to check the information and find the following error: <pre class="brush:php;toolbar:false">WARNING:?IPv4?forwarding?is?disabled
WARNING:?bridge-nf-call-iptables?is?disabled
WARNING:?bridge-nf-call-ip6tables?is?disabled</pre>
?Use the command
Edit the configuration file and add the following code to the file: <pre class="brush:php;toolbar:false">net.bridge.bridge-nf-call-ip6tables=1
net.bridge.bridge-nf-call-iptables=1
net.bridge.bridge-nf-call-arptables=1
net.ipv4.ip_forward=1</pre>
?Then use the command
Restart the network and check docker info
again, the warning disappears. But it's still useless. The container on the bastion machine still cannot access the host machine through the bridge and cannot access the external network.
- Reset the bridge
- After using the command
to install the tool, use brctl show
Check the network bridge and you can find:
Use the docker network create [bridge name]
command to create a new network bridge and find the generated bridge id
is still 8000.0000000000
, create a container on the new bridge, and check again and there is no change, indicating that it is probably a problem with the bridge. ?Test again. At this time, the bridge
ip
is 172.17.0.1
and the container ip
is 172.0.0.2
. The host function is found. ping
The network bridge is connected, but the container cannot be connected. The container cannot connect to the network bridge and cannot connect to the host, let alone the external network, so there must be a problem with the network bridge. <h3 id="問(wèn)題解決">問(wèn)題解決</h3>
<p>??這里<code>docker network
生成新的網(wǎng)橋不行,說(shuō)明docker
的network
存在問(wèn)題,我們利用剛才下載的bridge-utils
來(lái)創(chuàng)建網(wǎng)橋。
??首先暫停docker
服務(wù),利用指令:
service?docker?stop
??添加網(wǎng)橋:
brctl?addbr?br0
??添加ip
字段:
ip?addr?add?172.16.0.1/24?dev?br0
??啟用網(wǎng)橋br0
:
ip?link?set?dev?br0?up
??查看網(wǎng)絡(luò)br0
:
??修改docker
默認(rèn)網(wǎng)橋:
vim?/etc/docker/daemon.json
??添加字段:
"bridge":"br0"
??重啟docker
:
service?docker?start
??此時(shí)查看網(wǎng)橋:
??在沒(méi)有掛載容器前,依舊是8000.000000000000
。運(yùn)行測(cè)試容器:
docker?run?-itd?--name?busy_test?busybox
??查看What should I do if docker cannot ping the host?:
??此時(shí)容器掛載在網(wǎng)橋上了,再次查看網(wǎng)橋id
:
??說(shuō)明已經(jīng)其作用,進(jìn)入測(cè)試容器內(nèi)部,What should I do if docker cannot ping the host?:
??成功!
??補(bǔ)充:這里使用docker network
新建網(wǎng)橋,沒(méi)有用,發(fā)現(xiàn)新建網(wǎng)橋掛載容器后,其bridge id
依舊不變,沒(méi)有起作用,說(shuō)明堡壘機(jī)上的docker network
可能存在問(wèn)題。
問(wèn)題補(bǔ)充:
??上面的問(wèn)題是創(chuàng)建自定義網(wǎng)橋,然后在自定義網(wǎng)橋上連接容器a
和b
,結(jié)果宿主機(jī)無(wú)法ping
通a
、b
,且進(jìn)入容器內(nèi)部后,兩個(gè)容器無(wú)法ping
通自定義網(wǎng)絡(luò),但能彼此相通。
??查了很多資料,發(fā)現(xiàn)了這篇文章。博主說(shuō)問(wèn)題原因是系統(tǒng)內(nèi)核的網(wǎng)橋模塊bridge.ko
加載失敗導(dǎo)致,解決問(wèn)題的方案是升級(jí)內(nèi)核或升級(jí)系統(tǒng)。
??升級(jí)centos
內(nèi)核參考這篇。
??升級(jí)完成后,重裝Docker
,自定義網(wǎng)橋和容器,成功!不再有網(wǎng)絡(luò)問(wèn)題。
推薦學(xué)習(xí):《docker視頻教程》
The above is the detailed content of What should I do if docker cannot ping the host?. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

1. The Origin of .NETCore When talking about .NETCore, we must not mention its predecessor .NET. Java was in the limelight at that time, and Microsoft also favored Java. The Java virtual machine on the Windows platform was developed by Microsoft based on JVM standards. It is said to be the best performance Java virtual machine at that time. However, Microsoft has its own little abacus, trying to bundle Java with the Windows platform and add some Windows-specific features. Sun's dissatisfaction with this led to a breakdown of the relationship between the two parties, and Microsoft then launched .NET. .NET has borrowed many features of Java since its inception and gradually surpassed Java in language features and form development. Java in version 1.6

To develop a complete Python Web application, follow these steps: 1. Choose the appropriate framework, such as Django or Flask. 2. Integrate databases and use ORMs such as SQLAlchemy. 3. Design the front-end and use Vue or React. 4. Perform the test, use pytest or unittest. 5. Deploy applications, use Docker and platforms such as Heroku or AWS. Through these steps, powerful and efficient web applications can be built.

Docker and Kubernetes are leaders in containerization and orchestration. Docker focuses on container lifecycle management and is suitable for small projects; Kubernetes is good at container orchestration and is suitable for large-scale production environments. The combination of the two can improve development and deployment efficiency.

There are three ways to view the process information inside the Docker container: 1. Use the dockertop command to list all processes in the container and display PID, user, command and other information; 2. Use dockerexec to enter the container, and then use the ps or top command to view detailed process information; 3. Use the dockerstats command to display the usage of container resources in real time, and combine dockertop to fully understand the performance of the container.

Deploying a PyTorch application on Ubuntu can be done by following the steps: 1. Install Python and pip First, make sure that Python and pip are already installed on your system. You can install them using the following command: sudoaptupdatesudoaptinstallpython3python3-pip2. Create a virtual environment (optional) To isolate your project environment, it is recommended to create a virtual environment: python3-mvenvmyenvsourcemyenv/bin/activatet

Deploying and tuning Jenkins on Debian is a process involving multiple steps, including installation, configuration, plug-in management, and performance optimization. Here is a detailed guide to help you achieve efficient Jenkins deployment. Installing Jenkins First, make sure your system has a Java environment installed. Jenkins requires a Java runtime environment (JRE) to run properly. sudoaptupdatesudoaptininstallopenjdk-11-jdk Verify that Java installation is successful: java-version Next, add J

An efficient way to batch stop a Docker container includes using basic commands and tools. 1. Use the dockerstop$(dockerps-q) command and adjust the timeout time, such as dockerstop-t30$(dockerps-q). 2. Use dockerps filtering options, such as dockerstop$(dockerps-q--filter"label=app=web"). 3. Use the DockerCompose command docker-composedown. 4. Write scripts to stop containers in order, such as stopping db, app and web containers.

There are two ways to compare the differences in different Docker image versions: 1. Use the dockerdiff command to view changes in the container file system; 2. Use the dockerhistory command to view the hierarchy difference in the image building. These methods help to understand and optimize image versioning.
