Solve the problem that the docker container cannot ping the external network

Solve the problem that the docker container cannot ping the external network

Today, when I was building a redis environment in docker, I found that yum could not pull resources and could not access the Internet, and reported the following error:

http://mirrors.aliyun.com/centos/6.10/extras/x86_64/Packages/epel-release-6-8.noarch.rpm: [Errno 14] PYCURL ERROR 6 - "Couldn't resolve host 'mirrors.aliyun.com'"
Trying other mirror.
http://mirrors.neusoft.edu.cn/centos/6.10/extras/x86_64/Packages/epel-release-6-8.noarch.rpm: [Errno 14] PYCURL ERROR 6 - "Couldn't resolve host 'mirrors.neusoft.edu.cn'"
Trying other mirror.
http://mirrors.nwsuaf.edu.cn/centos/6.10/extras/x86_64/Packages/epel-release-6-8.noarch.rpm: [Errno 14] PYCURL ERROR 6 - "Couldn't resolve host 'mirrors.nwsuaf.edu.cn'"
Trying other mirror.
http://mirrors.shu.edu.cn/centos/6.10/extras/x86_64/Packages/epel-release-6-8.noarch.rpm: [Errno 14] PYCURL ERROR 6 - "Couldn't resolve host 'mirrors.shu.edu.cn'"
Trying other mirror.
http://mirrors.sohu.com/centos/6.10/extras/x86_64/Packages/epel-release-6-8.noarch.rpm: [Errno 14] PYCURL ERROR 6 - "Couldn't resolve host 'mirrors.sohu.com'"
Trying other mirror.
http://mirrors.tuna.tsinghua.edu.cn/centos/6.10/extras/x86_64/Packages/epel-release-6-8.noarch.rpm: [Errno 14] PYCURL ERROR 6 - "Couldn't resolve host 'mirrors.tuna.tsinghua.edu.cn'"
Trying other mirror.
http://mirrors.zju.edu.cn/centos/6.10/extras/x86_64/Packages/epel-release-6-8.noarch.rpm: [Errno 14] PYCURL ERROR 6 - "Couldn't resolve host 'mirrors.zju.edu.cn'"
Trying other mirror.

Testing wget

wget http://mirrors.163.com/.help/CentOS6-Base-163.repo

Result error

unknown host mirrors.163.com

Test ping

Inside the container

ping www.baidu.com

The result is still failure

ping: unknown host www.baidu.com

Open another terminal, enter the host (not the container), and run the ping command test. It is OK. It can be basically determined that it is a docker problem, not a network problem.

Workaround

Stop all containers and restart docker

service docker restart

Content Extension

6 solutions for network failure in Docker container

1. Use the –net:host option

2. Use –dns option

3. Change DNS server

4. No need for dnsmasq

5. Rebuild the docker0 network

6. Modify /etc/hosts directly in docker

The above is the detailed content of solving the problem that the docker container cannot ping the external network. For more information about the docker container cannot ping the external network, please pay attention to other related articles on 123WORDPRESS.COM!

You may also be interested in:
  • Use of environment variables in Docker and solutions to common problems
  • Docker solves the problem that the terminal cannot input Chinese
  • Docker exposes port 2375, causing server attacks and solutions
  • Install Jenkins with Docker and solve the problem of initial plugin installation failure
  • When setting up Jenkins in Docker environment, the console log shows garbled Chinese characters when building tasks
  • Solution to the problem that docker logs cannot be retrieved
  • Share the problem of Ubuntu 19 not being able to install docker source
  • Docker FAQ

<<:  jQuery implements dynamic tag event

>>:  Summary of basic SQL statements in MySQL database

Recommend

Use of TypeScript Generics

Table of contents 1. Easy to use 2. Using generic...

View the port number occupied by the process in Linux

For Linux system administrators, it is crucial to...

Vue scaffolding learning project creation method

1. What is scaffolding? 1. Vue CLI Vue CLI is a c...

TypeScript generic parameter default types and new strict compilation option

Table of contents Overview Create a type definiti...

Detailed process of getting started with docker compose helloworld

Prerequisites Compose is a tool for orchestrating...

Vue implements three-dimensional column chart based on echarts

The three-dimensional column chart consists of th...

How to use CocosCreator to create a shooting game

Analyze the production steps: 1. Prepare resource...

Detailed explanation of how Node.js middleware works

Table of contents What is Express middleware? Req...

Why MySQL database avoids NULL as much as possible

Many tables in MySQL contain columns that can be ...

Analysis of GTK treeview principle and usage

The GtkTreeView component is an advanced componen...

Vue mobile terminal determines the direction of finger sliding on the screen

The vue mobile terminal determines the direction ...

MySQL 5.7.18 installation tutorial and problem summary

MySQL 5.7.18 installation and problem summary. I ...