docker - How does docker-compose create aliases for link ips
问题描述
when running docker-compose, all containers have network aliases to the ip of the other containers running in the network. How are these aliases created ?
I need to recreate an alias in an nginx container within a Kubernetes cluster, because nginx conf doesn't allow environment variables and I reverse proxy requests to another container from there. I would normally edit the /etc/hosts file, but since docker-compose doesn't, I'm wondering how is the alias created and if I could do it the same way within my kubernetes cluster.
解决方案
In a kubernetes cluster, there is a DNS server service deployed by default.
kubectl get svc
should show the DNS service IP address.
You can find the DNS server IP address inside the containers /etc/resolv.conf
file too.
See here for more info.
You can specify additional entries in container's /etc/hosts
file using HostAliases. See here.
Snip:
apiVersion: v1
kind: Pod
metadata:
name: hostaliases-pod
spec:
restartPolicy: Never
hostAliases:
- ip: "127.0.0.1"
hostnames:
- "foo.local"
- "bar.local"
- ip: "10.1.2.3"
hostnames:
- "foo.remote"
- "bar.remote"
推荐阅读
- android - ActivityView的剪辑内容
- python - 如何在 Pandas 的 lambda 函数中使用 str.replace?
- r - 随机生成具有指定聚类系数的网络
- c++ - 转换罗马数字阿拉伯形式的基本程序?
- algorithm - Search first appearence in matrix under time complexity demands
- ios - 我怎么知道 Instagram 按钮已被选中?
- label - Vue-Chartjs onComplete 自定义标签 - 防止闪烁
- android - React Native api 在物理 Android 设备上不起作用(错误:网络错误)
- powershell - 使用 -eq 或 -ne 在 Powershell 中检测变音符号
- php - Telegram Inline Bot 不会显示