Create Dockerfiles for these applications
- Install Docker Desktop or Rancher Desktop (OSS)
- Make sure
docker -vworks from your terminal.
- Create a
Dockerfilefor each app, starting with the lang/tech you feel most comfortable with. - Your
Dockerfilemust be split into a build stage and a runner/app stage. - It must start the application when using
docker run
- Build:
docker build <./dir/with/dockerfile> -t <image-tag>(assumes Dockerfile dir is also build context)- Serialized:
DOCKER_BUILDKIT=0 docker build ...(debug each layer/cmd, by using printed sha as image-tag)
- Serialized:
- Re-tag:
docker tag <image-tag> <new-image-tag> - Images & their sizes:
docker images
- What's running?
docker ps - Run:
docker run <image-tag>(runs interactively until done or ctrl+c) - Keep running:
docker run --detached <image-tag>(runs in background until done) - Debug:
docker run -it --entrypoint /bin/bash <image-tag>
Simple image that extends Ubuntu 24.04 distro with some extra network debugging tools. Useful to understand base-images and layering
- Start with
FROM ubuntu24.04and then make sure curl and dnsutils are installed in the container image. - Start and execute into the container image, then try using the
curlandnslookuptools.
Static nginx-based web-app which hosts static HTML files.
- Create a static http web-app that hosts our static replacement
index.htmlfile. - You can use
nginx,python -m http.serveror any other way to host the statichtml/index.htmlfile via HTTP on an exposed port.
Simple scratch-based go app that just outputs the contents of a .txt file
- This task is purely educational. Inspect the Dockerfile and learn about
scratch - Build the container image and check its disk-size!
docker images | grep <image-tag>
Simple hello-world app in Java
- Follow Ole's guide on containerizing a Java app
Simple hello-world app in .NET 10
Create a Dockerfile for the app and test it!
- Follow Microsoft's guide on containerizing dotnet apps
- See https://learn.microsoft.com/en-us/dotnet/core/docker/build-container?tabs=windows&pivots=dotnet-10-0
- Minimize layers by combining related commands.
- Split Dockerfile into build and runtime stages! (massively reduces image size)
- Use .dockerignore to reduce the build-context and image size.
- Pin versions! Use
FROM alpine:3.19.0rather than justalpineoralpine:latest.- Use of
:stabletags might be a good idea if available.
- Use of
- Add metadata to your container images!
LABEL org.opencontainers.image.source="https://github.com/org/repo" LABEL org.opencontainers.image.version="1.0.0" LABEL org.opencontainers.image.description="My custom base image"
- Use
docker compose up -dto build and launch all our containers (in the same virtual network). - Try executing into on of the running containers (
docker compose exec -it <service-name> /bin/bash). - Try to fetch our HTML website from
static-web-appvia theubuntu-debuggercontainer. - Try fetching logs from our
static-web-appvia cmddocker compose logs -f <service-name>, can you see the fetch? - Try reducing some of the container image sizes! Check with
docker images.