Karol Selak
Karol Selak

Reputation: 4804

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. Trying to run docker-compose up I get an error:

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. Maybe that's the matter of some specific version or environment?

Upvotes: 6

Views: 3927

Answers (2)

Yonatan Huber
Yonatan Huber

Reputation: 308

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

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

so in your case that would be:

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

Upvotes: 9

DannyB
DannyB

Reputation: 14846

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.
  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.

Different names for the docker-compose file

In order to use an alternative file, you can take one of these approaches:

  1. Run docker-compose with the --file argument:
$ docker-compose --help

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

  1. Set the COMPOSE_FILE environment variable prior to running any docker-compose command.

Upvotes: 0

Related Questions