嗨,我正在查看上面的示例并尝试运行 docker swarm stack,但出现以下错误。不知道我在这里缺少什么。
docker-compose.yml
services:
nginx:
image: nginx
hostname: '{{.Node.Hostname}}'
version: '3.3'
docker堆栈部署测试-c docker-compose.yml
但低于输出/错误:来自守护程序的错误响应:rpc 错误:代码 = InvalidArgument desc = 扩展主机名失败: 模板:扩展:1:7:在 <.Node.Hostname> 处执行“扩展”: 无法评估类型结构 { ID string } 中的字段主机名
这是我的 docker-info 输出:
docker 信息容器:
12 运行:0 暂停:0 停止: 12 张图片:41 服务器版本:18.03.1-ce 存储驱动:devicemapper 池名称:docker-253:1-2490377-pool 池 区块大小:65.54kB 基础 设备大小:10.74GB 支持文件系统:
提前致谢。
我用 compose 的
version: '3.3'
和 version: '3.4'
尝试了你的设置。
根据 https://docs.docker.com/engine/reference/commandline/service_create/#create-services-using-templates 主机名是您可以使用模板字符串的字段之一,因此这应该可以正常工作。
创建堆栈后,我使用
验证了主机名$ docker inspect test_nginx | grep name
"com.docker.stack.namespace": "test"
"com.docker.stack.namespace": "test"
"Hostname": "{{.Node.Hostname}}",
所以我认为这个问题要么已经在最新版本的 docker 中得到修复,要么是你的主机设置有些奇怪。