简体   繁体   English

docker-compose 更改主容器的名称

[英]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.我有一个 docker-compose 文件,但它在前端文件夹中。 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我正在使用 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 文档相关,您可以使用以下命令设置项目名称:

docker-compose -p app up --build

with -p app to set your compose container name to app .使用-p app将您的撰写容器名称设置为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.在引用您的main container时,您可能指的是项目名称,您通常可以通过-p标志设置该名称。 (See other answers) (查看其他答案)

For docker-compose , you can set the top level variable name to your desired project name.对于docker-compose ,您可以将顶级变量name设置为所需的项目名称。

docker-compose.yml file: docker-compose.yml 文件:

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

Use -p to specify a project name使用 -p 指定项目名称

Each configuration has a project name.每个配置都有一个项目名称。 If you supply a -p flag, you can specify a project name.如果提供 -p 标志,则可以指定项目名称。 If you don't specify the flag, Compose uses the current directory name.如果您不指定标志,Compose 将使用当前目录名称。

Calling docker-compose --profile frontend up will start the services with the profile frontend and services without specified profiles.调用docker-compose --profile frontend up将启动带有配置文件前端的服务和没有指定配置文件的服务。 You can also enable multiple profiles, eg with docker-compose --profile frontend --profile debug up the profiles frontend and debug will be enabled您还可以启用多个配置文件,例如使用docker-compose --profile frontend --profile debug up配置配置文件前端并启用调试

Also refer https://docs.docker.com/compose/profiles/另请参阅https://docs.docker.com/compose/profiles/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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