The Docker Compose usage

We can start by using the ever-so-helpful --help switch on the docker-compose command. We will see a lot of output and will sift through it after the following output:

$ docker-compose --help

Define and run multi-container applications with Docker.

Usage:
  docker-compose [options] [COMMAND] [ARGS...]
  docker-compose -h|--help

Options:
  -f, --file FILE           Specify an alternate compose file (default: docker-compose.yml)
  -p, --project-name NAME   Specify an alternate project name (default: directory name)
  --verbose                 Show more output
  -v, --version             Print version and exit

Commands:
  build              Build or rebuild services
  help               Get help on a command
  kill               Kill containers
  logs               View output from containers
  port               Print the public port for a port binding
  ps                 List containers
  pull               Pulls service images
  restart            Restart services
  rm                 Remove stopped containers
  run                Run a one-off command
  scale              Set number of containers for a service
  start              Start services
  stop               Stop services
  up                 Create and start containers
  migrate-to-labels  Recreate containers to add labels
  version            Show the Docker-Compose version information

The Docker Compose options

Looking at the help output, we can see that the list is categorized as Usage, Options, and Commands. The Usage section is how you will need to structure your commands to run them successfully. Next is the Options section that we will look at now:

Options:
  -f, --file FILE           Specify an alternate compose file (default: docker-compose.yml)
  -p, --project-name NAME   Specify an alternate project name (default: directory name)
  --verbose                 Show more output
  -v, --version             Print version and exit

So, as we can see from the previous output of the docker-compose --help command, there are two sections: an Options section as well as a Commands section. We will first look at the items in the Options section and next look at the Commands section.

There are four items in the Options section:

  • -f: If you are using Docker Compose outside the folder where the docker-compose.yml file exists or if you are not naming it docker-compose.yml, then you will need to specify the -f flag. By default, when you initiate the Docker Compose commands, they are meant to be done in the directory where your docker-compose.yml file is located. This helps in keeping things consistent, organized, as well as less convoluted.
  • -p, --project-name: The -p option will allow you to give a name to your project. By default, Docker Compose uses the name of the folder you are currently running the Docker Compose commands from. This allows you to override it.
  • --verbose: The --verbose switch allows you to run Docker Compose in a way that you can see the output of items about the image(s) being used, such as:
    • The command used to start the containers
    • The CPU shares being used in the container
    • The domain name being used
    • Whether an entry point was used and if so, what it is
  • -v, --version: This will simply print the version number of the Docker Compose client being used.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset