As in Chapter 13, Deploying a Replica Set, we start by defining a docker-compose.yml file that defines the five containers we use in this illustration to model a sharded cluster: one container to host the config server, one to host the mongos instance, and three to represent shards. At the top of the file, we place the version directive.
This informs Docker Compose that this file follows directives compatible with version 3:
version: "3"
We then define services, starting with the first member of the sharded cluster. In this definition, you can see that we assign a name of learn-mongo-shard-1 to the Docker container and a hostname of shard1. The image directive defines a name for the image (ultimately derived from the official MongoDB Docker image) created by Docker Compose, as shown here:
services:
learn-mongodb-shard-1:
container_name: learn-mongo-shard-1
hostname: shard1
image: learn-mongodb/shard-1
Under volumes...