Docker Compse allows us to easily run multiple containers alongside each other, and best mirror our production environments. It aims to simplify this process by using a docker-compose.yml file to define the services. After this module, you should be comfortable with most tasks required to interact and manage a local container environment.
For this module, create a new Git repo for your Docker Compose work in Module 12.
If you haven't already, it is recommended that you read through each of the official documentation resources listed below and follow some of the links within each resource to help clarify specific tools and their purposes.
Resources and articles:
- What is Docker?
- Official docker-compose.yml Reference
- Official Docker Engine Docs
- Official Docker Compose Docs - (common use cases)
- Docker Self Paced Training
-
Create a file called docker-compose.yml
-
In your docker-compose.yml file, add a new service called
hello-containerwith the imagehello-world -
Create a new file called docker-compose-module.txt, and paste the output of
docker-compose up.If you look from the top of the output, you should be able to see the process that docker-compose goes through to start the
hello-containerservice. A new image is pulled, started, and exits, just like you would do by hand to start and stop a container. -
Commit your changes and push up.
-
Create a new directory called scripts.
-
In that new directory, create a new executable file called welcome-compose.sh containing the following:
#!/bin/bash
echo 'Hello, Docker Compose!'
- Update the
hello-worldservice in your docker-compose.yml file to use therealpage/alpine-bash:3.3from module 11. - In the docker-compose.yml file, mount the new
./scriptsdirectory as the/home/scriptsdirectory within thehello-containerservice. - Update the
hello-containerservice to run the welcome-docker.sh file and paste the output ofdocker-compose up. - Commit your changes and push up.
- Create a new service called
data-containerthat uses thealpine:3.3image, mounts the same volumes as thehello-containerservice, and runs/bin/ash. - Update the
hello-containerservice to mount the volumes from thedata-containerservice and paste the output ofdocker-compose up. - Commit your changes and push up.
When you are done, verify you have pushed your changes to GitHub. Please create a tag called v1.0 with a message of "ready for review" in your docker compose repo. Be sure your tags are pushed to the remote repository and are visible in GitHub.
Create an issue titled Review Module 12 - Docker Compose and @mention your mentor and team leader.