在 docker compose 中获取主机的主机名
Get host's hostname in docker compose
docker 群的 {{.Node.Hostname}} 在 docker-compose 中的等价物是什么。我正在尝试在我的 docker-compose.yml 文件中获取主机的主机名。
谢谢
您可以使用 docker 的 extra_hosts option 撰写。
首先您需要在您的主机中为您的主机环回定义一个别名。例如:
sudo ifconfig lo0 alias 10.100.100.1/24
然后 在您的 docker-compose 文件中:
extra_hosts:
- "my_hostname:10.200.10.1"
检查结果运行 this :
$ docker exec -it your_container_name /bin/bash
// run a command to check connectivity to your host machine.like this:
// supposed you have a website running on host machine
$ wget my_hostname/index.html
$ cat index.html
docker 群的 {{.Node.Hostname}} 在 docker-compose 中的等价物是什么。我正在尝试在我的 docker-compose.yml 文件中获取主机的主机名。 谢谢
您可以使用 docker 的 extra_hosts option 撰写。
首先您需要在您的主机中为您的主机环回定义一个别名。例如:
sudo ifconfig lo0 alias 10.100.100.1/24
然后 在您的 docker-compose 文件中:
extra_hosts:
- "my_hostname:10.200.10.1"
检查结果运行 this :
$ docker exec -it your_container_name /bin/bash
// run a command to check connectivity to your host machine.like this:
// supposed you have a website running on host machine
$ wget my_hostname/index.html
$ cat index.html