Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What if the network request in the docker container is slow?

2025-04-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly shows you "what to do if the network request in the docker container is slow". The content is easy to understand and clear. I hope it can help you solve your doubts. Let the editor lead you to study and learn the article "how to do the slow network request in the docker container".

First, the network mode of docker

1 、 none

When configured as none, the docker container network cannot be input or output and is isolated from the rest of the world.

2 、 bridge

The default is bridge mode, and docker has its own virtual network card, which obtains the network from the host by bridging.

3 、 host

When host is specified, the network card of the host is directly exposed to the container and surf the Internet directly through the network of the host. For example, if you want to get the redis service 127.0.0.1 6357 on the host, you have to use this method, but it is relatively insecure.

4 、 container

Use the network of other containers

2. Dns analysis of docker

The docker container is essentially a linux, so the parsing method of dns is the same as linux. The priority is to find / etc/hosts file. Domain names like localhost are written in this file, such as:

127.0.0.1 localhost

If the docker container link other containers, the domain name of link will also be added here, such as:

Docker run-- name app--link app-redis:redis-d ubuntu

There will be more in hosts.

172.17.0.3 app-redis 038c8388e4a1

Find the / etc/hosts file, then the / etc/resolv.conf file:

Domain localnameserver 192.168.65.1nameserver 192.168.65.10

Third, solve the problem of slow network requests in the docker container

After packet capture testing and other analysis, it is found that the network request is slow, which mainly occurs in dns parsing, so dns optimization is mainly adopted:

If you are requesting an api from your own private network, you can modify the / etc/hosts file directly. If it is a request from a public network, you can change the nameserver in / etc/resolv.conf.

The docker container is certainly not directly implemented by modifying the file, but can be achieved through the command of run:

# add hostdocker run-- name app-- add-host='api.embbnux.com:10.98.10.98'-d ubuntu# specify dns serverdocker run-- name app-- dns=223.5.5.5-- dns=8.8.8.8-d ubuntu

This accelerates the time of the dns parsing phase in the docker container

The above is all the contents of the article "what to do about slow network requests in the docker container". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report