2 min read

Project: Home lab foundations - Docker

Project: Home lab foundations - Docker
Photo by Rubaitul Azad / Unsplash

To do most of the things I'll write about here, you'll need to have an understanding of containers. You will also need to develop a habit of reading documentation.

An image is a packaged blueprint that includes application code, libraries, runtimes, configurations required to run that software.

A container is a running instance of an image.

Unlike a virtual machine, a container will share the host operating system kernel rather than emulating an OS - so containers are faster and use fewer resources.

Docker is the most popular way to run containers. There are other ways of running containers - but since it's the most used, we'll stick with it for now.

Docker is available on all platforms, but it's native to Linux. Windows and Mac create a lightweight linux VM. This is because Docker relies on native Linux kernel features that do not exist in Mac OS or Windows. Instructions on how to install Docker are plentiful:

  • Windows: you can use Docker Desktop - requires WSL or Hyper-V.
  • Linux: Instructions available - the Engine, CLI and Compose will be required. Docker Desktop is available and installs all 3.
  • MacOS: Docker Desktop does exist, but I personally prefer to run alternatives like Orbstack (uses Docker under the hood, but provides a better experience than the Docker Desktop app).

We will be making use of Docker Compose extensively in future posts. Docker Desktop and Orbstack include Compose. There are many ways to use Docker Compose - I think the most straightforward for beginners is using something like Portainer or Dockge, but there's nothing stopping you from creating .yaml files manually and using the terminal to deploy from the file.

Dockge may not be as mature, but it definitely is more user friendly than Portainer.

The Github instructions are the best place to start for Dockge. Once done and if the instructions have been followed, your Dockge instance will be available on http://localhost:5001 by default. It can also help with converting docker run commands to compose files. A summary, pasted from the Github page:

# Create directories that store your stacks and stores Dockge's stack
mkdir -p /opt/stacks /opt/dockge
cd /opt/dockge

# Download the compose.yaml
curl https://raw.githubusercontent.com/louislam/dockge/master/compose.yaml --output compose.yaml

# Start the server
docker compose up -d

# If you are using docker-compose V1 or Podman
# docker-compose up -d

For Portainer - there are a few ways, but to simplify - open a Terminal window in your Docker environment and do:

# First, create the volume portainer will use to store its data
docker volume create portainer_data

# Then deploy the container
docker run -d -p 8000:8000 -p 9443:9443 --name portainer --restart=always -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer-ce:lts

Then your Portainer instance will be available on https://localhost:9443.

What can I do with this?

You can self host a multitude of open source applications, or self host a website like the one you're reading this on. Or your own very own app if you ever get into developing. It's a great start for a home server, and something I will build on in future posts.