docker dns

news/2025/1/7 7:04:13/文章来源:https://www.cnblogs.com/lightsong/p/18653104

docker容器添加自定义hosts

https://www.cnblogs.com/erlou96/p/13884130.html

方案一

动时增加hosts,参考自docker docs

 
docker run -d --name test1 \ --add-host test1.a:1.2.3.4 \ local/test

 

方案二

docker-compose.yml文件指定,参考自stackoverflow

 
test2: build: local/test extra_hosts: test1.a: 1.2.3.4 test1.b: 4.3.2.1

 

Add entries to container hosts file (--add-host)

https://docs.docker.com/reference/cli/docker/container/run/#add-host

You can add other hosts into a container's /etc/hosts file by using one or more --add-host flags. This example adds a static address for a host named my-hostname:

 
 
 docker run --add-host=my-hostname=8.8.8.8 --rm -it alpine

/ # ping my-hostname
PING my-hostname (8.8.8.8): 56 data bytes
64 bytes from 8.8.8.8: seq=0 ttl=37 time=93.052 ms
64 bytes from 8.8.8.8: seq=1 ttl=37 time=92.467 ms
64 bytes from 8.8.8.8: seq=2 ttl=37 time=92.252 ms
^C
--- my-hostname ping statistics ---
4 packets transmitted, 4 packets received, 0% packet loss
round-trip min/avg/max = 92.209/92.495/93.052 ms

You can wrap an IPv6 address in square brackets:

 
 
 docker run --add-host my-hostname=[2001:db8::33] --rm -it alpine

The --add-host flag supports a special host-gateway value that resolves to the internal IP address of the host. This is useful when you want containers to connect to services running on the host machine.

It's conventional to use host.docker.internal as the hostname referring to host-gateway. Docker Desktop automatically resolves this hostname, see Explore networking features.

The following example shows how the special host-gateway value works. The example runs an HTTP server that serves a file from host to container over the host.docker.internal hostname, which resolves to the host's internal IP.

 
 
 echo "hello from host!" > ./hello
 python3 -m http.server 8000
Serving HTTP on 0.0.0.0 port 8000 (http://0.0.0.0:8000/) ...
 docker run \
  --add-host host.docker.internal=host-gateway \
  curlimages/curl -s host.docker.internal:8000/hello
hello from host!

The --add-host flag also accepts a : separator, for example:

 
 
 docker run --add-host=my-hostname:8.8.8.8 --rm -it alpine

 

 

Networking overview

https://docs.docker.com/engine/network/

 

Understanding Docker DNS

https://medium.com/@prajwal.chin/understanding-docker-dns-2ed4b070a0

When working with Docker containers, networking plays a crucial role in enabling communication between containers and the outside world. One fundamental aspect of container networking is DNS (Domain Name System), which allows containers to discover and communicate with each other using domain names instead of relying on IP addresses. In this post, we’ll explore Docker DNS and how it facilitates container communication.

🔎 What is DNS?

The Domain Name System (DNS) is a hierarchical decentralized naming system that translates human-readable domain names, like www.example.com, into IP addresses, such as 192.0.2.1. DNS acts as the phonebook of the internet, enabling computers to locate and connect with each other using recognizable names.

🐋 Docker DNS Resolution

In the context of Docker, DNS resolution refers to the process of translating domain names into IP addresses for containers running on the same network. Docker provides a built-in DNS service that allows containers to resolve domain names to the correct IP addresses within the same Docker network. By default, Docker containers use the embedded DNS resolver provided by the Docker daemon.

🔌 Docker Default DNS Configurations

When you create a Docker network, it automatically configures DNS resolution for containers within that network. By default, Docker uses the following DNS configurations:

1️⃣ Docker daemon as the DNS server: Containers use the Docker daemon’s embedded DNS resolver, which listens on the default DNS server IP address 127.0.0.11. This DNS server handles DNS queries from containers and forwards them to the appropriate DNS server for resolution.

2️⃣ Container name as hostname: Docker automatically assigns a unique hostname to each container, which is the container’s name. This hostname can be used for internal DNS resolution within the Docker network.

3️⃣ Automatic DNS aliasing: Docker provides automatic DNS aliasing for container-to-container communication. Each container’s name is mapped to an IP address in the Docker network’s DNS server. This allows containers to resolve other containers’ domain names by using their respective names as hostnames.

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/864297.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

遗留了很久的功能终于搞定/QTreeWidget自定义节点/添加删除修改分组

一、前言说明 这个功能看起来简单,实际上也确实简单,以前没搞的时候还以为很难,难点就是如何存储这个任意层级的树状列表信息,近期大环境经济很差,刚好有空把这个功能搞定,其实二维表格的方式存储这种任意层级树结构就可以,就是子节点需要指定父节点,父节点为空表示顶层…

2025年正在重塑行业的10款AI代理工具

序言:本文的作者列出来的这10款AI代理工具是您认可的吗? 作为一名深入AI开发领域超过十年的开发者,我见过无数工具声称要颠覆我们构建AI代理的方式。有些工具确实实现了夸下的海口——但更多的则没有。 经过几个月的亲身测试以及与同行开发者的讨论,我整理出了一份2025年真…

[cause]: TypeError: e_.createContext is not a function (Next.js 15)

开发 Next.js 项目遇到报错: [cause]: TypeError: e_.createContext is not a function 出现这个报错的原因是在 Next.js 项目中,在 Server Component 中使用了MUI组件,但是MUI组件没有做 SSR 适配就会导致这个报错。 解决办法 解决办法就是在文件顶部添加 use client 声明…

golang自带的死锁检测并非银弹

网上总是能看到有人说go自带了死锁检测,只要有死锁发生runtime就能检测到并及时报错退出,因此go不会被死锁问题困扰。 这说明了口口相传知识的有效性是日常值得怀疑的,同时也再一次证明了没有银弹这句话的含金量。 这个说法的杀伤力在于它虽然不对,但也不是全错,真真假假很…

2025多校冲刺省选模拟赛2

2025多校冲刺省选模拟赛2\(T1\) A. aw \(10pts/20pts\)部分分\(10 \sim 20pts\) :枚举每一种定向方案,略带卡常。点击查看代码 const int p=998244353; struct node {int nxt,to; }e[200010]; int head[100010],dis[1010][1010],a[100010],b[100010],g[2][100010],cnt=0; b…

jamovi 2.6 (Linux, macOS, Windows) - 统计软件

jamovi 2.6 (Linux, macOS, Windows) - 统计软件jamovi 2.6 (Linux, macOS, Windows) - 统计软件 open statistical software 请访问原文直链:https://sysin.org/blog/jamovi/ 查看最新版。原创作品,转载请保留出处。 作者主页:sysin.orgjamovi适用于桌面和云的开放式统计软…

读数据保护:工作负载的可恢复性26商用数据备份方案

商用数据备份方案1. 备份简史 1.1. 20世纪80年代中期大家都还没有意识到,运行着商用UNIX操作系统的大型工作环境里,应该配备一款商用的备份软件或某种自动的磁带系统 1.2. 1993年备份工作全都是通过shell脚本与cron job形式的计划任务来实现的1.2.1. 脚本总是假定服务器中需要…

OpenCV和OpenVX有什么联系和区别

OpenCV和OpenVX有什么联系和区别 联系和区别是:OpenCV是一个基于Apache2.0许可(开源)发行的跨平台计算机视觉和机器学习软件库。OpenVX 实现了跨平台加速处理,OpenVX在嵌入式和实时性系统中,可以更好地发挥它的优势,在某些场合配合OpenCV的强大功能,可以实现更好的效果。…

SPIR-V生态系统概述

SPIR-V生态系统SPIR-V生态系统,如图1-42所示。图1-42 SPIR-V生态系统 1.4.2 OpenVX路线图OpenVX路线图,如图1-43所示。图1-43 OpenVX路线图 OpenVX跨供应商视觉与推理 基于图形的高级抽象实现可移植、高效的视觉处理。 1)处理器供应商创建、优化和发布优化OpenVX的驱动程序。…

4本书推荐《智能汽车传感器:原理设计应用》、《AI芯片开发核心技术详解》、《TVM编译器原理与实践》、《LLVM编译器原理与实践》

4本书推荐《AI芯片开发核心技术详解》、《智能汽车传感器:原理设计应用》、《TVM编译器原理与实践》、《LLVM编译器原理与实践》由清华大学出版社资深编辑赵佳霓老师策划编辑的新书《AI芯片开发核心技术详解》已经出版,京东、淘宝天猫、当当等网上,相应陆陆续续可以购买。该…

Easysearch 可搜索快照功能,看这篇就够了

可搜索快照功能改变了我们对备份数据的查询方式。以往要查询备份数据时,要先找到备份数据所在的快照,然后在一个合适的环境中恢复快照,最后再发起请求查询数据。这个处理路径很长,而且很消耗时间。可搜索快照功能将大大简化该处理路径,节约时间。 角色设置 相信你对节点角…

基本共射极放大电路的分析

静态分析利用直流通路求Q点(静态工作点)\[I_{BQ}=\frac{V_{BB}-V_{BEQ}}{R_{b}} \]一般硅管\(V_{BE}=0.7V\),锗管\(V_{BE}=0.2V\),\(\beta\)已知 \[I_{CQ}=\beta I_{BQ} \]\[V_{CEQ}=(\frac{V_{CC}-I_{CQ}}{R_{c}}-I_{CQ})R_L \]动态分析交流通路分析画小信号等效模型\[r_{…