skip to Main Content

I deploy my docker containers with docker stack deploy -c docker-compose.yml my-service

Problem: docker service ls shows the NAME always with my-service_my-service, generated from docker-compose:

services:
  my-service:
    #container_name #not supported when using 'docker stack deploy'
    ports:
      - "8090:8080"
    ...

This is due to the fact that the name in docker stack deploy is taken as stack name, and the service form docker-compose as service name.

Thus, the resulting name is stackname_servicename.

Question: how can I force the service being named without a stack prefix?

2

Answers


  1. Chosen as BEST ANSWER

    As it's not possible to work around that, maybe best would be to give the application only a generic service name, like app:.

    services:
      app:
        ports:
          - "8090:8080"
        ...
    

    This way, docker stack deploy my-service would result in my-service_app. Which reads way better.


  2. This behavior is a technical prerequisite, so it is not possible to change. You may change the stackname and the servicename but not the composition of both. The name has to be individual, if not you might have different services in different networks with the same name and therefore ID and alias.

    You may build your own "compose" by creating a bash-script with docker service create --name to reach that goal, then it is in your own responsibility.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search