Search code examples
dockerdocker-compose

Docker container error: unknown flag: --build


After an update of Docker Desktop (on windows 11) from 4.34.0 4.34.2, trying to run:

docker compose up --build

results in this error: unknown flag: --build

Why is this happening?


Solution

  • The error you're seeing is likely due to a change in how Docker Compose V2 handles flags after your update. In Docker Compose V2, the docker-compose command was integrated as a subcommand of the docker CLI (docker compose).

    So basically, if docker compose up --build gives an error, try using the standalone docker-compose up --build. This should still work as expected.

    You also want to check that you’re using Docker Compose V2 by running:

    docker compose version
    

    If you're on V2, try resetting Docker Desktop if the issue persists.

    For more details, you can check the differences between Compose V1 and Compose V2 in the official documentation here: Docker Compose V2 Documentation

    This should explain the issue and provide the correct approach.