Home Learning How to Docker in 2023
Post
Cancel

Learning How to Docker in 2023

Audience

SRE, Dev ops, Platform engineering

Introduction

The purpose of this post is to assist you in starting your Docker learning journey by sharing resources, tips, and methods that I have acquired over the years. It is based on my personal experiences from the last 8 years or so spent in and around the Docker ecosystem, as well as from experiences helping my colleagues at work who are starting from scratch. If you are new to the Docker ecosystem, it can be quite overwhelming to begin because there is so much information available. The lessons here are some of the things I wish I had known when I first started.

If you have experience with Docker and happen to be reading this, please consider sharing this beginner’s guide with friends or colleagues who could benefit from it. Additionally, I would appreciate hearing from you on Twitter or Mastodon if you have any favorite resources or tips that you think are missing.

Optimize for How you prefer to learn

When it comes to learning, it’s important to find an approach that works best for you. This is where the concept of bias learning comes in. Bias learning means that you tailor your learning approach to your personal preferences and goals. For instance, some people may find that they learn best by reading, while others learn better through visual aids or hands-on experiences.

Getting started:

  1. For mature projects like Docker or Kubernetes, I usually recommend starting with the official documentation to get oriented on what the tool in question does and learn the basics of how to install it into your environment. You don’t need to read the entirity but consider starting with the overview and getting started sections as a first order of business.
  2. The YouTube recording of the intro workshop by Shy Ruparel from Docker Con 2022 is both approachable and a good overview of how to get started with a total runtime of 2 hours 40 minutes.
  3. If you have a LinkedIn learning subscription and prefer a more structured approach, the Beginning Docker course is worth a look: Beginning Docker. If you have a Pluralsight subscrtion, getting started with docker is a equaly good.
  4. Bret Fisher has a bunch of great Docker content on his YouTube channel. You can find his channel here: https://www.youtube.com/@BretFisher/videos I highly recommend looking through the many videos and picking out what is interesting.
  5. Some amount of hands-on experience with Docker is essential. Whilst getting your own environment setup is highly recommended, a quicker way is to use a pre-built cloud hosted environment. In the old days, the go-to used to be Katacoda but that site sadly went the way of the dodo. A promising replacement that you may find helpful is play-with-docker.com: training.play-with-docker.com.

Basic tip for searching for topics on YouTube. Pay attention to the number of views on search results.

If you have a favorite docker into video, would love to hear about it! HMU on Twitter or Mastodon if you have any questions or comments.

Tooling esentials

  1. Docker desktop is a great place to start as, if you are new to the space the GUI can make it easier to discover and learn concepts. Plus docker desktop is available on all popular platforms. One thing to watch out for is the license which was revised in August 2021 such that it is no longer free to use in all cases. Worth being aware of this and checking out some of the free alternatives.
  2. Starting with the GUI is great, but I would recommend spending some time in the terminal of your choice gaining familiarity with the docker CLI. If you are on Linux I always recommend talking a look at Podman as a docker alternative as it’s completely free for all types of usage including commercial and it’s command compatible with the docker CLI. There is also a fledgling GUI project for Podman which, whilst not as mature as docker desktop, has the basics and is completely free.
  3. If you are using Windows, it’s well worth installing Windows Subsystem for Linux version 2 (WSL2) with your Linux distro of choice and enabling docker support said distro as described here https://docs.docker.com/desktop/windows/wsl/. The benefit of this approach over legacy mode desktop is that the Docker utility Linux VM shares the same resources with the WSL Linux environment which enables scenarios such as sharing resources such as volumes with great mount performance. Another reason to do this is support for remote container scenarios as described here.

CLI tip: When using docker in the terminal, make sure you learn how to use command autocompletion. This makes learning the CLI easier and removes repetitive typing. I watch so many beginners struggling to type and remember commands unnecessarily. Get into the habit of using command completion. Type docker, a few characters of the command, hitting tab whenever you get stuck. This works not only for remembering docker sub-commands but also command arguments, for example if you type docker rm or docker image rm . Command completion is enabled by default in docker, for podman look at the help for ‘podman completion’

Going Deeper

  1. If you are going to be using Docker in your job day to day it’s well worth going deeper by investing some time in structured learning program, for example if you are going to be managing Docker in production: Pluralsight Managing docker in production
  2. If you are curious about docker internals or are also interested in progressing from docker to kubernetes, worth drilling in to better understand container fundamentals and some of the underlying Linux constructs such as cgroups, namespaces and junctionpoints. For this I recommend taking the excellent Container Fundamentals course (this is a paid course).
  3. To get a more hands on view of what it takes to leverage Linux primitives to get something like a container working check out Liz Rice’s containers from scratch repo.
  4. Another great source of internals infor can be found in Kal Hendiaks’s on linux repo.

Self Assesment

If you were joining my team and I was assessing your knowledge of docker, these are some of the things I’d be asking you to explain to me:

Concepts

  • DockerFile
  • Container Image
  • Container Registry
  • Container Instance
  • Image Tags
  • Volumes and volume mounts
  • OCI image format
  • Image Digests
  • Image Layers
  • Interactive vs TODO background
  • Linux namespaces
  • Linux CGroups
  • Linux Junction points
  • Windows Containers
  • Distroless Linux container images
  • Rootless Linux container images
  • CPU architecture and OS: Linux/Windows, ARM64v8, AMD64
  • Networking IP address, listening rules (127.0.0.1 vs 0.0.0.0), ports
  • Environment variables
  • Access control

Techniques / scenarios

Basic

  1. Pull an nginx docker image from a public container registry using docker or podman
  2. Run a local nginx container from nginx image using docker or podman
  3. Build a local image from a Dockerfile using docker or podman (refernece https://github.com/clarkezone/cloudnativeplayground/tree/main/testapps/golang/simplehttpserver)
  4. List local images
  5. Delete a local image
  6. Tag a local image
  7. Push a local image to a public registry (docker or ghcr)
  8. Run a container and mount a volume
  9. Run a container setting environment variables
  10. Run a static website using nginx connecting a volume with static content and exposing ports (See Running a basic web server.
  11. Run a conatiner in interactive mode with terminal attached
  12. List running and stopped containers
  13. Manually clean up stopped containers
  14. Run a container enabling automatic clean up on exit

Intermediate

  1. List tags for an image in public registry (docker or ghcr)
  2. Create a private registry e.g. Azure Container Registry
  3. Push an image to a private registry
  4. list digests
  5. Run a multi-container image using Docker Compose
  6. Detatch from running container / attach to detached running container
  7. Enable command completion for the docker command
  8. use ${pwd} to map current working directory as volume for testing
  9. Building a container image as part of a CI/CD pipeline

Advanced

  1. Use docker exec into a running container
  2. Override entrypoint for container image
  3. Reclaim disk space from unused images
  4. Perform local multi-image builds

Reference

There are many great tool lists that I use for discovering and keeping track of what’s hot in the world of Docker. These two are well worth bookmarking if you are interested in keeping up: https://collabnix.github.io/dockertools/ and https://github.com/veggiemonk/awesome-docker.

Wrap-up

Thanks for reading this far! I hope you’ve been able to learn something new. Would love to know how you get on your journey into the fun world of Docker and Containers. Stay in touch here Twitter or Mastodon

This post is licensed under CC BY 4.0 by the author.