ScanSkill

docker compose CLI

docker compose command is used to build and manage multiple services in docker containers. If you can use -f flag to specify the location of Compose configuration file. Also, you can pass multiple configuration files with -f. When you pass multiple files, compose combines them into a single configuration.

Example

$ docker-compose -f docker-compose.yml -f docker-compose.admin.yml run cloudyfox_db 

Here, let’s say, docker-compose.yml has a configuration, webapp as a service:

webapp:
  image: cloudyfox/web
  ports:
    - "5000:5000"
  volumes:
    - "/data"

And if the docker-compose.admin.yml also has the same service configuration, then any matching fields will override the previous file.

webapp:
  build: .
  environment:
    - DEBUG=1

Note: Here, -f flag is optional. If it’s not provided on the command line, compose uses the current working directory and its parent directories to look for a docker-compose.yml and docker-compose.override.yml file. If both files are present in the current directory then, both will be combined into a single configuration.