我的docker compose文件位于/ documents文件夹中,当我使用docker-compose up时,它将文件夹名称附加到服务名称(myappv1)。
documents_myappv1_1
这样做的目的是什么?为什么不能只是
myappv1_1
最佳答案
Docker Compose使用项目名称来允许用户部署multiple isolated environments on a single host。默认情况下,项目名称将使用包含docker-compose.yml
的文件夹的名称。
您可以通过以下方式更改容器的命名行为:
-p
选项(例如docker-compose -p project_name up
),这将导致容器被命名为project_name_myappv1_1
container_name
选项指定自定义容器名称,即使在不同的部署中,该名称也将保持不变作为per doc:
Compose uses a project name to isolate environments from each other. You can make use of this project name in several different contexts:
- on a dev host, to create multiple copies of a single environment, such as when you want to run a stable copy for each feature branch of a project
- on a CI server, to keep builds from interfering with each other, you can set the project name to a unique build number
- on a shared host or dev host, to prevent different projects, which may use the same service names, from interfering with each other
The default project name is the basename of the project directory. You can set a custom project name by using the
-p
command line option or theCOMPOSE_PROJECT_NAME
environment variable.
关于docker - 在docker compose中将文件夹名称前缀为容器名称的目的是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64369368/