简体   繁体   English

自定义文件而不是 docker-compose.yml

[英]Custom file instead of docker-compose.yml

I start to work with a new project using Docker and I can see there is no docker-compose.yml file there, but a few files like docker-compose.myname1.yml , docker-compose.myname2.yml instead. I start to work with a new project using Docker and I can see there is no docker-compose.yml file there, but a few files like docker-compose.myname1.yml , docker-compose.myname2.yml instead. Trying to run docker-compose up I get an error:尝试运行docker-compose up出现错误:

ERROR: 
        Can't find a suitable configuration file in this directory or any
        parent. Are you in the right directory?

        Supported filenames: docker-compose.yml, docker-compose.yaml

So I wonder if that's possible for a Docker project to work without the docker-compose.yml file and if it is, what conditions should be met.所以我想知道 Docker 项目是否可以在没有docker-compose.yml文件的情况下工作,如果是,应该满足什么条件。 Maybe that's the matter of some specific version or environment?也许这是某些特定版本或环境的问题?

https://docs.docker.com/compose/reference/ https://docs.docker.com/compose/reference/

"Options: -f, --file FILE Specify an alternate compose file (default: docker-compose.yml)" “选项:-f, --file FILE 指定一个备用的撰写文件(默认值:docker-compose.yml)”

so in your case that would be:所以在你的情况下,这将是:

docker-compose up -f dockcer-compose.myname1.yml
docker-compose up -f dockcer-compose.myname2.yml

There are two different issues presented in your question:您的问题中有两个不同的问题:

The reason for getting an error出现错误的原因

  1. When running docker-compose up , you must be in a directory that contains docker-compose.yml (or '.yaml ), as indicated by the error you are receiving.运行docker-compose up ,您必须位于包含docker-compose.yml (或'.yaml )的目录中,如您收到的错误所示。
  2. The reason you are getting an error is either because there is no such file in the current directory, or (less likely) the environment variable COMPOSE_FILE is set to something else.您收到错误的原因是因为当前目录中没有这样的文件,或者(不太可能)环境变量COMPOSE_FILE设置为其他值。

Different names for the docker-compose file docker-compose 文件的不同名称

In order to use an alternative file, you can take one of these approaches:为了使用替代文件,您可以采用以下方法之一:

  1. Run docker-compose with the --file argument:使用--file参数运行docker-compose
$ docker-compose --help

  -f, --file FILE     Specify an alternate compose file
                      (default: docker-compose.yml)

  1. Set theCOMPOSE_FILE environment variable prior to running any docker-compose command.在运行任何docker-compose命令之前设置COMPOSE_FILE环境变量

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

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