如何在Docker Swarm中的全局服务中设置主机名 [英] How to set hostname in global service in Docker Swarm
本文介绍了如何在Docker Swarm中的全局服务中设置主机名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个服务作为全局服务(ELK Metricbeat)部署到了Docker Swarm集群。
I have a service deployed to my Docker Swarm Cluster as global service (ELK Metricbeat).
我希望每个服务的主机名都与换句话说,运行中的节点(主机)的主机名是什么?
I want to each of this service to have a hostname the same as the hostname of the running node (host)?
如何在yml文件中实现相同的结果,例如:
in another word, how I can achieve the same result in the yml file such as:
docker run -h `hostname` elastic/metricbeat:5.4.1
这是我的yml文件:
metricbeat:
image: elastic/metricbeat:5.4.1
command: metricbeat -e -c /etc/metricbeat/metricbeat.yml -system.hostfs=/hostfs
hostname: '`hostname`'
volumes:
- /proc:/hostfs/proc:ro
- /sys/fs/cgroup:/hostfs/sys/fs/cgroup:ro
- /:/hostfs:ro
- /var/run/docker.sock:/var/run/docker.sock
networks:
- net
user: root
deploy:
mode: global
我尝试过:
hostname: '`hostname`'
hostname: '${hostname}'
,但没有成功。
有什么解决方法吗?
谢谢您。
推荐答案
对于任何来这里的人:
services:
myservice:
hostname: "{{.Node.Hostname}}-{{.Service.Name}}"
否需要更改入口点(至少在部署时是成群的)
No need to alter entry point ( at least on swarm on deploy )
这篇关于如何在Docker Swarm中的全局服务中设置主机名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文