Difficulty: Beginner
Estimated Time: 10 minutes

When working with multiple containers, it can be difficult to manage the starting along with the configuration of variables and links. To solve this problem, Docker has a tool called Docker Compose to manage the orchestration of launching of containers.

In this scenario, you will build a simple Python web application running on Docker Compose. The application uses the Flask framework and maintains a hit counter in Redis. While the sample uses Python, the concepts demonstrated here should be understandable even if you’re not familiar with it.

In this scenario, we explored how you can use Docker Compose to manage the orchestration of multi-container applications.

Don’t stop now! The next scenario will only take about 10 minutes to complete.

Docker Compose

Step 1 of 6

Step 1 - Creating Docker Image

To complete this step, you need to complete following tasks:

Task 1 : Create Dockerfile

To complete this task, you need to copy the following code:

FROM python:3.4-alpine
COPY app.py /code
RUN pip install flask redis
CMD ["python", "app.py"]

This tells Docker to:

  • Build an image starting with the Python 3.4 image.
  • Set the working directory to /code.
  • Copy the file app.py into the path /code in the image.
  • Install the Python dependencies.
  • Set the default command for the container to python app.py.

Task 2 : Run Docker Build

Using the docker build command to build the image. You can give the image a friendly name by using the -t <image_name> option.

To complete this task you need to execute the following code: docker build --tag flask-redis-app .