问题描述
使用以下命令部署此撰写文件的堆栈时:
When deploying a stack of this compose file using:
docker stack deploy -c docker-compose.yml myapp
service-name:
image: service-image
namelike-property: my-custom-service-name // here I would like to know the property
生成的服务名称为 myapp_service-name
我希望它由 my-custom-service-name
推荐答案
对于两个服务之间的通信,如果两个服务都在同一网络中,则可以使用撰写文件中定义的serviceName(在您的情况下,您的服务名称为service-name)。
For communication between services you can use the serviceName as defined in the compose file (in your case your service name is service-name) if both services communicating are in the same network.
当您执行 docker service ls
时,堆栈名称将显示在每个服务之前。这样做是因为可能有两个不在共享网络中且具有相同名称的服务。您无法更改该名称,这样做也没有任何意义,因为该名称并不重要,实际上只是一个ID。但是,您可以更改堆栈的名称以获取$ {StackNameILike}:$ {ServiceNameILike}
When you do docker service ls
the stackname will be shown before every service. That's done because its possible to have two services with the same name which are not in a shared network. You can't change that and it wouldn't make sense to do that because that name is not important and is actually just an ID. You can however change the name of your stack to get ${StackNameILike}:${ServiceNameILike}
这篇关于如何在docker-compose中更改Docker堆栈生成的服务名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!