Skip to content

🕹 Challenges & Exploration

You as a student need to fill in these assignments and learning goals by yourself. At the start of each next chapter the lecturer will, together with class, review these in an overall sense but will not give the full, word-by-word, solution for you to simply sit back and download. So it is important that you have completed the work yourself before the review starts in class and you can correct where needed.

You are not allowed to use AI like ChatGPT or Bing Copilot on the exam, but you are here! Leverage these new tools to speed up and give structure to your notes and documents. For example, ask to put material in Markdown format!

📝 After completing these challenges, you should be able to:
  • Describe how the COPY command is involved in transferring files.
  • List the ports required for web traffic and explain what role is of the EXPOSE instruction.
  • Describe the steps to construct a Dockerfile for containerizing a basic Apache-based website.
  • Describe the process of installing Apache from scratch using the apk package manager in a Dockerfile.
  • Explain how to execute SQL scripts upon a mysql container initialization.
  • Differentiate between the usage of ENV and ARG in Dockerfiles.
  • Explain how to develop a basic Python application container image.
  • Describe what a requirements.txt file is in the context of Python applications and why it is useful.
  • Describe the usage of either CMD or ENTRYPOINT to define the container's startup command.
  • List the steps to minimize container size using an small Python base images and give examples of these images.
  • Implement a Dockerfile for a Python Hello World application.
  • Explain how to use pip to install necessary Python libraries within the container.

🌐 A website, but Apache

Redo the demo exercise where you made a Dockerfile starting from an nginx base image, but now find and use an Apache base image instead.

Use the same index.html and logoimage.png. Name the image testwebsiteapache.

🗻 A website, but from the ground up

Redo the previous exercise, but now start from an Alpine base image (alpine:3.14) instead and install the needed components to come to the same end result.

Beware that you are now installing Apache from scratch instead of relying on the prebuilt container! You might have to use different filepaths or settings, read through this article to get the required information.

Use the same index.html and logoimage.png. Name the image testwebsiteapache.

🗃 Your own custom MySQL image

In your Full Stack course you will soon be using a MySQL database. How about being prepared and making our own custom MySQL database to use in the exercises, data included!

Start from an MySQL base image then make sure that:

  • this .sql file gets run when the container is made. There is a specific way to do this!
  • the root password is 1234.

Name the image fullstackmysql.

You already know how to provide an environment variable when running a container with docker run via -e.

Now also look up how to use ENV and ARG in Dockerfiles and see:

  • What the are differences between both?
  • If you can still overwrite the environment variable provided in the Dockerfile with -e during a docker run?

Use your MySQL workbench or mysql cli in the container to check whether festivals like Tomorrowland and Rock Werchter are present in the festival tabel of the festivaldb to see if you were successful.

🐍 Your first Python image

Create your first Python app container image.

The app inside the eventual container should just print Hello World. You can use CMD or ENTRYPOINT in this Dockerfile. Look up what the difference between the two is.

Make sure that you try to get the smallest possible container size-wise. Name the image firstpythonapp.

🐍 Python todo image 1, Python hard

Take a look at the following Python file main.py.

py
import requests, os
url = "http://%s:%s%s" % ("jsonplaceholder.typicode.com", "80", "/todos/1")
# Send the request using the specified method
res = requests.request("GET", url)
# Print the status code, headers, and body of the response
print("Status:", res.status_code)
print("Headers:", res.headers)
print("Body:", res.text)

This code uses the requests library to do a HTTP GET request to https://jsonplaceholder.typicode.com/todos/1 and prints out the result.

Create a second Python app container image where you make sure the libraries are installed and the Python code can run. Name the image pythontodocaller.

🐍 Python todo image 2, Python harder

Look up what a requirements.txt file is in the context of Python applications and why it is useful.

Transition the previous exercise to using that system in the Dockerfile.

Name the image pythontodocaller2.

🐍 Python todo image 3, with a vengeance

Take a look at the following Python file main.py again.

py
import requests, os
# Construct the URL from the environment variables
# The % operator is used to format strings by replacing placeholders with values
# The placeholders are %s for strings and the values are given in parentheses after the %
url = "http://%s:%s%s" % (os.environ["PYHOSTNAME"], os.environ["PYPORT"], os.environ["PYPATH"])
# Send the request using the specified method
res = requests.request(os.environ["PYMETHOD"], url)
# Print the status code, headers, and body of the response
print("Status:", res.status_code)
print("Headers:", res.headers)
print("Body:", res.text)

This code now expects 4 different environment variables instead of the hardcoded values. It then does a HTTP request to a certain URL with a certain method, based on these variables and prints out the result.

Create a third Python app container image where you already set these enviroment values of the application in the Dockerfile. Make sure the app still does a GET request to https://jsonplaceholder.typicode.com/todos/1. Name the image pythontodocaller3.

π