如何在Docker中设置主机名? [英] How Do I Set Hostname in Docker Compose?

查看:5076
本文介绍了如何在Docker中设置主机名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的docker-compose.yml文件中,我有以下。但是,容器不会接收主机名值。任何想法?

  dns:
image:phensley / docker-dns
hostname:affy
域名:affy.com
卷:
- /var/run/docker.sock:/docker.sock


解决方案

这似乎正常工作。如果我把你的配置文件放到一个文件中:

  $ cat> compose.yml<< EOF 
dns:
image:phensley / docker-dns
主机名:affy
域名:affy.com
卷:
- /var/run/docker.sock:/docker.sock
EOF

然后提起来:

  $ docker-compose -f compose.yml up 
创建tmp_dns_1 ...
附加到tmp_dns_1
dns_1 | 2015-04-28T17:47:45.423387 [dockerdns] table.add tmp_dns_1.docker - > 172.17.0.5

然后检查容器内的主机名,一切似乎都很好:

  $ docker exec -it stack_dns_1 hostname 
affy.affy.com


In my docker-compose.yml file, I have the following. However the container does not pick up the hostname value. Any ideas?

dns:
  image: phensley/docker-dns
  hostname: affy
  domainname: affy.com
  volumes:
    - /var/run/docker.sock:/docker.sock

解决方案

This seems to work correctly. If I put your config into a file:

$ cat > compose.yml <<EOF
dns:
  image: phensley/docker-dns
  hostname: affy
  domainname: affy.com
  volumes:
    - /var/run/docker.sock:/docker.sock
EOF

And then bring things up:

$ docker-compose -f compose.yml up
Creating tmp_dns_1...
Attaching to tmp_dns_1
dns_1 | 2015-04-28T17:47:45.423387 [dockerdns] table.add tmp_dns_1.docker -> 172.17.0.5

And then check the hostname inside the container, everything seems to be fine:

$ docker exec -it stack_dns_1 hostname
affy.affy.com

这篇关于如何在Docker中设置主机名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆