...

/

Docker Compose and TestContainers

Docker Compose and TestContainers

Learn how to use TestContainers-scala to run Docker containers from a Docker Compose file.

We'll cover the following...

In this lesson, we’ll use TestContainers-scala with a Docker Compose file describing the infrastructural dependencies of our application. The only dependency we’ll need is a Docker container running LocalStack. While a Docker Compose file isn’t necessary, it’s a good way to understand how the approach works.

The Docker Compose file

The first thing we have to do when we want to use TestContainers-scala with a Docker Compose file is write a file listing all our external services. In the following examples, we’ll be using only LocalStack, so our Docker Compose file will only have one service.

Press + to interact
version: "3.8"
services:
localstack:
image: localstack/localstack:2.0.2
restart: always

The file closely follows the format required by Docker Compose. We specify the version and the list of services. For each one, we can state the Docker image that should be pulled to run the container, a restart policy, and a port mapping. Note how we’re not ...