169

I have a non-default docker-compose file name (docker-compose-test.yml). There is only one service defined in it.

I am starting the container using "docker-compose -f docker-compose-test.yml up"

I am trying to stop the container started above using docker-compose down, but it is not working.

I am getting below 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

I understand that it is looking for default docker compose file name. Is there a way to specify the custom config file name during docker-compose down?

3
  • 6
    Are you using the same flag -f docker-compose-test.yml when running the down command??
    – Marc Nuri
    Commented Feb 10, 2018 at 6:36
  • @MarcNuri it worked. thanks! Commented Feb 10, 2018 at 7:24
  • Good news, I'll post an answer so that we can close the thread.
    – Marc Nuri
    Commented Feb 10, 2018 at 7:38

5 Answers 5

240

You should run the docker-compose down command with the same flags that when you started the containers.

docker-compose -f docker-compose-test.yml down

3
  • 18
    aaaand this should be in the official Docker docs, but it's still not. crazy!
    – Sliq
    Commented Sep 3, 2021 at 17:34
  • 1
    @Sliq docs.docker.com/compose/reference/…
    – m4heshd
    Commented Mar 8, 2022 at 15:46
  • 2
    Most people will probably read docs.docker.com/compose/reference/down though to look at what options are available. But the file option isn't mentioned there - I guess because it's an option for docker-compose, not the up/down commands.
    – coatesap
    Commented May 24, 2022 at 14:13
57

Note, that the syntax of docker-compose is such that -f needs to be before up/down, and thereafter -d:

docker-compose -f docker-compose.prod.yml up -d

If you put -f after up/down, it doesn't work, and also if you put -d before up/down you get the help display or an error. Down works of course without -d:

docker-compose -f docker-compose.prod.yml down
1
  • 7 years later and your answer is still good ! Crazy this hasn't been addressed. Commented Sep 28, 2022 at 13:02
26

You can create a .env file and add the following:

COMPOSE_FILE=docker-compose-test.yml
1
  • this is awesome! it is the only choice when you want '$ docker compose build' from non-standard compose config file
    – Alex
    Commented Apr 29, 2023 at 13:01
12

For whoever searching for docker compose V2 (new docker compose instead of docker-compose) in 2023

Specifying non default/standard docker compose file for docker compose v1 and v2 is same.

For docker compose V1 (docker-compose)

# for stopping
docker-compose -f docker-compose.yml down

# for creating
docker-compose -f docker-compose.yml up

For docker compose V2 (docker compose)

# for stopping
docker compose -f docker-compose.yml down

# for creating
docker compose -f docker-compose.yml up

Docker compose reference

10

If you use multiple files for docker-compose AND a custom name, you should write like this:

docker-compose -f docker-compose.yml -f docker-compose.override.yml -p custom_name down

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.