简体   繁体   中英

How to create a docker service without project name prefix in its name?

I have just started learning Docker to build Microservices. I am trying to understand and follow eShopOnContainers app as my reference application to understand all the concepts. For testing, I created two ASP.Net Web API services and created a docker-compose.yml file to test if I can run them. I am able to run the services but one thing I have noticed is that service names are not very tidy. They contain the folder name prefix. For example here is part of my docker-compose.yml file

services:
  orders-api:
    image: orders-api
    build:
      context: .
      dockerfile: src/Services/Orders/Dockerfile
    ports:
      - "1122:80"

I am expecting that when this service runs, it should be named orders-api but instead it's name becomes micrservicestest_orders-api_1. MicroservicesTest is the folder name of my project. I was trying to find a way around it but it seems like this is the limitation of Docker itself. The only thing I don't understand is that when I run the sample app of eShopOnContainers, their services have readable names without any prefixes. How are they able to generate more readable service names?

Can you please tell me what am I missing here?

docker-compose automatically adds prefix to your containers' name. By default, prefix is the basename of the directory that you executed docker-compose up .

You can change it by using $ docker-compose --project-name MY_PROJECT_NAME , but this is not you want.

You can specify containers' name by using container_name: .

services:
  orders-api:
    image: orders-api
    build:
      context: .
      dockerfile: src/Services/Orders/Dockerfile
    container_name: orders-api
    ports:
      - "1122:80"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM