简体   繁体   中英

docker-compose change name of main container

I have a simple frontend and backend app. And I have a docker-compose file but it's inside frontend folder. So when I run it both frontend and backend containers are under frontend container (it takes name of the folder) how can I rename this main container? I am using version 3.9

version: "3.9"
services:
  be_service:
    container_name: backend
    build:
      context: ../backend
      dockerfile: ./Dockerfile
    ports:
      - "8089:8080"
  fe_service:
    container_name: frontend
    build:
      context: ./
      dockerfile: ./Dockerfile
    ports:
      - "8088:80"
    depends_on:
      - be_service

Related to Docker Compose docs you can set your project name with:

docker-compose -p app up --build

with -p app to set your compose container name to app .

我认为您的 docker compose 文件是正确的,并且要更改 co,您可以使用 contains_name 指令,但我认为您应该在要运行应用程序时运行此命令:

docker-compose up --build

When refering to your main container , you are probably refering to the project name, which you could usually set via the -p flag. (See other answers)

For docker-compose , you can set the top level variable name to your desired project name.

docker-compose.yml file:

version: "3.9"
name: my-project-name
services:
  myService:
    ...

Use -p to specify a project name

Each configuration has a project name. If you supply a -p flag, you can specify a project name. If you don't specify the flag, Compose uses the current directory name.

Calling docker-compose --profile frontend up will start the services with the profile frontend and services without specified profiles. You can also enable multiple profiles, eg with docker-compose --profile frontend --profile debug up the profiles frontend and debug will be enabled

Also refer https://docs.docker.com/compose/profiles/

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