'Start docker containers with swarm without appending a random slug after the container names
I searched on stackoverflow and on other websites if I could start my docker containers with swarm and keep the same naming as with compose - service_name_1, service_name_2 ... , service_name_n, however, I found no solution to my problem and docker swarm keeps appending a random slug after the container names - service_name_1.slug.
As I am relatively new to docker swarm, I would like to ask if the naming convection of docker swarm can be altered before the containers start or if it could somehow be made deterministic, as this does not work with my setup and changing my whole setup is something, I would love to avoid.
Solution 1:[1]
There are two ways to deploy a service to the swarm:
using
docker service createcommand and to provide a name for your service, use the --name flag :docker service create --replicas 1 --name service_name alpine ping docker.com
using
docker stack deploy, all created services will be prefixed with the name of the stack 'stack_name'docker stack deploy -c docker-compose.yml stack_name
In swarm mode, the stackname will be shown before every service and every services is postfixed with .1 .2 to indicate instance number (scaling). 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.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | HAL9000 |
