Setting up complex environments
While the basic usage of Docker is pretty straightforward for basic setups, it can be bit overwhelming once you start to use it in multiple projects. It is really easy to forget about specific command-line options, or which ports should be published on which images. But things start to be really complicated when you have one service that needs to communicate with others. Single docker containers should only contain one running process.
This means that you really shouldn't put any additional process supervision tools, such as Supervisor and Circus, and should instead set up multiple containers that communicate with each other. Each service may use a completely different image, provide different configuration options, and expose ports that may or may not overlap.
The best tool that you can use in both simple and complex scenarios is Compose. Compose is usually distributed with Docker, but in some Linux distributions (for example, Ubuntu), it may not be available by default, and must be installed as a separate package from the packages repository. Compose provides a powerful command-line utility named docker-compose, and allows you to describe multi-container applications using the YAML syntax.
Compose expects the specially named docker-compose.yml file to be in your project directory. An example of such a file for our previous project could be as follows:
version: '3'
services:
webserver:
# this tell Compose to build image from
# local (.) directory
build: .
# this is equivalent to "-p" option of
# the "docker build" command
ports:
- "80:80"
# this is equivalent to "-t" option of
# the "docker build" command
tty: true
If you create such a docker-compose.yml file in your project, then your whole application environment can be started and stopped with two simple commands:
- docker-compose up
- docker-compose down