-
Notifications
You must be signed in to change notification settings - Fork 6
Docker Compose
There are various other Docker setups depending on your needs, this page provides some guidance and typical setups to use during development. It also provides additional details for you to customize your own Docker setup, depending on your current development focus.
Docker Compose is used to define multi-container Docker setups for local development and integration tests. It sets up a Docker network, so that containers can readily connect using obvious hostnames rather than localhost
. It also sets up shared volumes to simulate LHDI deployment environments.
Docker setups:
-
Platform Base setup (
docker-compose.yml
): includes Postgres, Redis, and RabbitMQ. This creates Docker volumes and a network required by other setups. -
Mocks setup (
mocks/docker-compose.yml
): defines containers that act as substitutes for External APIs and services; only used only for development and integration testing -
Domain setups (
domain-*/docker-compose.yml
): each defines containers for their respective domain
For configurability, a docker-compose.yml
file can use compose profiles to run a subset of defined containers. Examine the file to see what profiles are available for each Docker setup.
The environment variable COMPOSE_PROFILES
determines which containers are started by docker-compose
(or docker compose
). This allows developers to start only the containers they need for their current work.
For even further customization, create a local docker-compose.override.yml
(docs) but do not commit it to git.
The following instructions, assume the Docker container images have been built: ./gradlew docker
The Gradle tasks to start up and shut down the Docker setups are dockerComposeUp
and dockerComposeDown
. Alternatively, the equivalent docker compose
command can be used instead.
- Start up:
./gradlew :dockerComposeUp
(Note the:
, which will run thedockerComposeUp
task in only the root Gradle project).- Equivalent to
docker compose up -d
- Check that all containers are healthy:
docker ps -a
- Manually test: visit the RabbitMQ Management UI at http://localhost:15672/
- Equivalent to
- Shut down:
./gradlew :dockerComposeDown
or./gradlew :dockerComposeDown :dockerPruneVolume
- Equivalent to
docker compose down
ordocker compose down --volume
(respectively)
- Equivalent to
Containers defined in the Mocks setup are not needed for typical development, so they are not started by default.
- First, build the mock container images:
./gradlew -p mocks docker
- To run the Slack and bie-kafka mocks:
COMPOSE_PROFILES="kafka,slack" ./gradlew -p mocks :dockerComposeUp
- Equivalent to
cd mocks; COMPOSE_PROFILES="kafka,slack" ./gradlew :dockerComposeUp
- Equivalent to
cd mocks; COMPOSE_PROFILES="kafka,slack" docker compose up -d
- Equivalent to
COMPOSE_PROFILES="kafka,slack" docker compose -f mocks/docker-compose.yml up -d
- Equivalent to
- To run all the mocks:
COMPOSE_PROFILES="all" ./gradlew -p mocks :dockerComposeUp
Examine the mocks/docker-compose.yml
file to see what other profiles are available.
If you want the mock to be available as localhost
outside of the Docker Compose network, run it without Docker Compose -- for example:
docker run -d -p 20100:20100 --name mock-slack va/abd_vro-mock-slack
To run a container without the Platform Base, don't use Docker Compose. Instead run using Gradle task dockerStart
, for example to run the Domain-CC App: ./gradlew domain-cc:cc-app:dockerStart
. Prior to running the container, this task will automatically build the container image (./gradlew domain-cc:cc-app:docker
). To shut down the container:
./gradlew domain-cc:cc-app:dockerStop
./gradlew domain-cc:cc-app:dockerRemoveContainer # Optional
To run only a subset of the Platform Base, specify the containers declared in the docker-compose.yml
file and use the docker compose
command directly -- don't use the Gradle tasks. For example:
- To run only the Postgres DB and db-init containers:
docker compose up -d postgres-service db-init
. - To shut down, run
docker compose down
.
All containers are included in the all
COMPOSE_PROFILE, so use that profile to start all containers in a given Docker setup.
- Set up:
COMPOSE_PROFILES="all" ./gradlew dockerComposeUp
(Note the lack of:
, which will rundockerComposeUp
in all relevant Gradle projects, starting from the root project). - Shut down:
COMPOSE_PROFILES="all" ./gradlew dockerComposeDown
To start each setup individually, start the Platform Base first; the others can be started in any order:
export COMPOSE_PROFILES="all"
./gradlew :dockerComposeUp # start the Platform Base
./gradlew :domain-xample:dockerComposeUp
./gradlew -p mocks :dockerComposeUp
...
To stop each setup individually, shut down the Platform Base last:
export COMPOSE_PROFILES="all"
./gradlew :domain-xample:dockerComposeDown
./gradlew -p mocks :dockerComposeDown
...
./gradlew :dockerComposeDown # stop the Platform Base
When a subset of containers across several setups is consistently used, set COMPOSE_PROFILES
once and export it. The variable will be used for all subsequent commands, and any unknown profiles for a particular Docker setup is ignored.
For example, if development or testing involves only svc-bip-api and the bip-claims-api mock, then running:
export COMPOSE_PROFILES="bip"
./gradlew :dockerComposeUp
./gradlew -p mocks :dockerComposeUp
This will start svc-bip-api (due to COMPOSE_PROFILES="bip"
and :dockerComposeUp
), and the BIP Claims API mock (due to COMPOSE_PROFILES="bip"
and -p mocks :dockerComposeUp
).
Because Docker resources (containers, images, and volumes) may be overridden and recreated during development, occasionally clean up:
- To prune unreferenced Docker resources:
./gradlew :dcPruneAll
- Equivalent to:
docker container prune docker image prune docker volume prune