Using docker-compose files to target multiple environments The
docker-compose.*.yml
files are definition files and can be used by multiple infrastructures that
understand that format. The most straightforward tool is the docker-compose command.
Therefore, by using the docker-compose command you can target the following main scenarios.
Development environments When you develop applications, it is important to be able to run an application in an isolated
development environment. You can use the docker-compose CLI command to create that
environment or Visual Studio, which uses docker-compose under the covers.
The docker-
compose.yml file allows you to configure and document all your application’s service
dependencies (other services, cache, databases, queues, etc.). Using the docker-compose CLI
command, you can create and start one or more containers for each dependency with a single
command (docker-compose up).
The docker-compose.yml files are configuration files interpreted by Docker engine but also serve as
convenient documentation files about the composition of your multi-container application.
Testing environments An important part of any continuous deployment (CD) or continuous integration (CI) process are the
unit tests and integration tests. These automated tests require an isolated environment so they are
not impacted by the users or an
y other change in the application’s data.
With Docker Compose, you can create and destroy that isolated environment very easily in a few
commands from your command prompt or scripts, like the following commands:
docker-compose -f docker-compose.yml -f docker-compose-test.override.yml up -d
./run_unit_tests
docker-compose -f docker-compose.yml -f docker-compose-test.override.yml down
Production deployments You can also use Compose to deploy to a remote Docker Engine. A typical case is to deploy to a
single Docker host instance (like a production VM or server provisioned with
Docker Machine
).
If you are using any other orchestrator (Azure Service Fabric, Kubernetes, etc.), you might need to add
setup and metadata configuration settings like those in docker-compose.yml, but in the format
required by the other orchestrator.
In any case, docker-compose is a convenient tool and metadata format for development, testing and
production workflows, although the production workflow might vary on the orchestrator you are
using.