Difficulty: intermediate
Estimated Time: 45-60 minutes

BoxBoat Logo

Developer Workflow

Welcome to the last lab of Docker for Devs! In this lab, you will assume the role of a developer at a company that is migrating to Docker. One of your senior developers has mostly completed an application. Your job is to get the application to work properly with Docker and Docker-Compose.

Please email feedback to: [email protected]

Developer Lab

We need some help...

Help a Developer out, would ya?

Introduction

Hey, thanks for helping me out with this project. I just finished my first pass at this simple application. Now that everything is in roughly good shape, we want to go ahead and Dockerize it, so I'll need your help.

Application

The application is basic Python Flask, and I heard you've got some experience with that. There is plenty of documentation that you can find on Google. Basically, the user will access the website, type in their name, and then the webserver will wrap their name in some pretty HTML.

Configuration

The application should listen on port 5000, but our users will access the application via port 8080 on our load balancer. We will eventually deploy the application in high availability mode for Docker Swarm -- so make sure your health check works properly. You should wait at least 2 or 3 minutes to make sure the health check is good, I've heard that sometimes these issues take awhile to manifest.

If you have any questions, let us know!

Files

  1. app.py: the source code for our application
  2. templates/main.html: the HTML template to load our page
  3. templates/name.html: the HTML template to load a name
  4. build.sh: bash script to build our image
  5. start-test.sh: bash script to test our image
  6. stop-test.sh: bash script to tear down our test
  7. deploy.sh: bash script to deploy our image

TODO

  1. Run app.py locally to make sure it works (python app.py)
  2. Write a healthcheck endpoint in app.py
  3. Verify the healthcheck endpoint works (curl localhost:5000/healthz -- this should respond with "ok")
  4. Write the build.sh script -- this should execute docker image build, make sure to tag your imate (the -t parameter)
  5. Write your Dockerfile, using the provided template. Use sh build.sh to build your image
  6. Write the start-test.sh script -- this should execute docker container run to start your container
  7. Verify your container works, don't be afraid to access logs and start the container in interactive mode to verify functionality
  8. Write the stop.sh script -- this should execute docker container rm -f to stop your container
  9. Write the deploy.sh script -- this should tag your image with stable. If you have a Docker Hub account, configure the script to push there

Dockerfile Tips

  1. Choose a base image that makes sense
  2. You'll need to preserve the directory structure for app.py, as well as the templates directory
  3. If you are struggling, craft a docker container run with your base image, and try running your Dockerfile commands sequentially
  4. Regarding the health check, remember that curl and wget either save the file or write it to STDOUT. Whichever one you choose will determine if you need to pipe the output to /dev/null for the health check