User Tools

Site Tools


howto:specific:learndocker

This is an old revision of the document!


Learning Docker

This is a brief overview of using Docker, matching the contents of the 2025 Docker Workshop.

What is Docker?

Docker is a platform for containerising applications. This is like running applications in Virtual Machines (VMs), although with a smaller resource footprint and the advantage of being able to re-use base images to save setup. For most users Docker enables the rapid setting up of software, so if you do or are interested in self hosting then you should find this very useful.

The Docker Workflow

  1. Start with an application
  2. Write a Dockerfile that replicates the setup needed for the application
  3. Use the Docker Client to build your application into an image
  4. Then use the Client again to run the image as a container
  5. Manage the running and configuration of multiple containers with Docker Compose

Parts of the Docker architecture

Dockerfiles

Dockerfiles are text files placed in the root of a project directory with instructions to build a container. They are comprised of layers, where each layer is modification to the image created by every layer “beneath” it. As such Dockerfiles normally start with a Base Image that provides a useful reusable starting point. Any image can be used as a base image, but normally they are things like particular OSes, or environments for a particular language or library (Python, Java, Node, etc). An example from the workshop is provided below:

FROM python:3.10-alpine

# Install flask
WORKDIR /code
COPY requirements.txt /code
RUN pip3 install -r requirements.txt

# Copy the code to the image
COPY . .

# Open the flask port
EXPOSE 5000

CMD ["python", "FlaskApp/FlaskApp.py"]

Each line is a layer, and does the following:

  1. Loads the python 3.10 base image
  2. Moves into the /code directory
  3. Copies in the requirements file
  4. Installs the requirements
  5. Copies in the rest of the code
  6. Exposes the port the application uses
  7. Defines the command that runs when the container starts.
Images

Images are built from Dockerfiles. They are immutable collections of binaries, config files, libraries and other files that are needed to run a particular application. Base images are uploaded to registries and can save a lot of work in creating your own images. This ranges from particular operating system environments to entire ready-to-configure applications.

Containers

Containers are created from images. Containers are similar to virtual machines, but are not the same thing. They run applications in isolated, self-reliant environments. One of the advantages of Docker is that pretty much anywhere it runs, containers will run.

Compose

TODO

Workshop tasks

Below is the interactive tasks from the workshop for people to work through at their own pace. Familiarity with Linux and Git is expected. The workshop repo can be found here.

Setup

Sign up to Tardis if you haven't already and SSH into Sandbox. Clone the workshop repo:

git clone https://git.tardisproject.uk/emily747/docker-workshop-2025

Look inside the Dockerfile, what does each layer do?

Build an image

howto/specific/learndocker.1737032195.txt.gz · Last modified: 2025/01/16 12:56 by alexdavis