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

Blog    

Recommend

5 ways to migrate from MySQL to ClickHouse

Data migration needs to be imported from MySQL to...

Spring Boot layered packaging Docker image practice and analysis (recommended)

Table of contents 1. Prepare the springboot proje...

Detailed explanation of Nginx http resource request limit (three methods)

Prerequisite: nginx needs to have the ngx_http_li...

Summary and practice of javascript prototype chain diagram

Table of contents Prototype chain We can implemen...

Vue implements tree table through element tree control

Table of contents Implementation effect diagram I...

Implementation of mysql decimal data type conversion

Recently, I encountered a database with the follo...

JS code to achieve page switching effect

This article example shares the specific code of ...

How to analyze MySQL query performance

Table of contents Slow query basics: optimizing d...

js code to realize multi-person chat room

This article example shares the specific code of ...

HTML+CSS to create a top navigation bar menu

Navigation bar creation: Technical requirements: ...

Vue's new partner TypeScript quick start practice record

Table of contents 1. Build using the official sca...

Based on JavaScript ES new features let and const keywords

Table of contents 1. let keyword 1.1 Basic Usage ...

Bootstrap FileInput implements image upload function

This article example shares the specific code of ...