Skip to content

Latest commit

 

History

History

casestudy-containers-01

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 

Containerize an App Using Docker

This case study explores how to containerize a Python application using Docker. The intent is to complete a Dockerfile that properly containerizes the application while allowing for persistent storage to be used (for the app's DB), providing a flexible path to the database using environment variables, and being flexible with the mapped port.

The candidate must not only complete the Dockerfile but also complete a Bash script that will start the container.

Starting the Task

Prior to starting the work the database needs to be initialized. This is done by running the following command either from the code_start directory or the code_solution:

make DB_FILE=db/storage.db

The reason things are setup this way is to provide for flexible "grading" of the task. That is, while you provide a solution based on the overall question, grading will be able to easily modify the input data and parameters to ensure that the task was completed successfully, accounting for all of the constraints.

Documentation for the Question

We are slowly transitioning away from monolithic apps and starting to containerize components/services where it makes sense.

Our storage status API seems like a good, first candidate.

In your code directory you will find a Dockerfile and a script, app-start.sh. Some initial work has been done in each to containerize the storage status API.

You must do the following:

  • In Dockerfile
    • Indicate that the app will use TCP/80
    • Indicate that the app requires a volume, /app/db
    • Indicate the app uses an environment variable, STORAGE_API_DB
  • In app-start.sh, complete the docker run command such that
    • The ./db directory is mounted at /app/db in the container
    • The value of the DB_FILE environment variable is passed as STORAGE_API_DB to the container
    • The port specified in the environment variable APP_PORT is mapped to the app’s TCP/80

The STORAGE_API_DB variable must default to ./storage.db. When executed, the app should be accessible on port 8080, but this needs to be controllable with the APP_PORT environment variable. No other elements of the Dockerfile or app-start.sh script should be modified.

Upon completion, set the appropriate value for the APP_PORT environment variable, set the STORAGE_API_DB environment variable to /app/db/storage.db, and run ./app-start.sh. You should then be able to access JSON data from the app at http://localhost:8080/api/v1/status.

Note that successfully seeing the JSON data does not guarantee the task was done correctly.

Solution

The solution is provided in the code_solution directory with some comments in the Dockerfile and app-start.sh script as to what was done and why.