Docker is a great way to run your self hosted applications and services on many different operating systems and types of hardware.
It's one of the easiest ways to get into self-hosting your own applications and a great way to learn without breaking things in the rest of your system.
In this series we're going to run through:
- What Docker is and how it works?
- How to get Docker installed on a Raspberry Pi or Windows Machine?
- How to run your first Docker container?
What is Docker?
Docker uses the Docker Engine to create containers that hold everything needed to run a particular piece of code or a executable program on almost any computer.
These containers are run independently from the rest of the machine similar to a virtual machine but with a lot less power needed.
The containers are isolated from the rest of the machine and can be run locally, remotely or in the cloud as their filesystem is self contained.
Docker Containers
Containers can be used to run almost any piece of software like a File Server, Web Browser or Full Operating System.
Here's an explanation from Docker themselves.
"A container is a standard unit of software that packages up code and all its dependencies so the application runs quickly and reliably from one computing environment to another. A Docker container image is a lightweight, standalone, executable package of software that includes everything needed to run an application: code, runtime, system tools, system libraries and settings." - *What is a Container? | Docker.com*
What is a Container? | Docker
A container is a unit of software that packages code and its dependencies so the application runs quickly and reliably across computing environments.
https://www.docker.com/resources/what-container/
These containers can be destroyed and then re-created quickly with the choice of either storing the data for the config to use again or reset to start fresh.
This allows you to upgrade or replace running containers with little to almost no down time, individually or all at once.
This can make keeping your infrastructure rolling along a lot easier and without anyone really noticing you've changed anything.
Docker Images
Docker Images are created by members of the community, software companies and Docker themselves.
Think of them as a shrunk down version of the program you would normally download to install an application like Chrome.
A Docker Image contains a specific set of instructions and files to create the environment needed to run a program or execute code.
There's a whole catalogue of different images that you can download from the official Docker Hub
There are images for everything from a Website CRM application like Ghost, which is what this blog is running on to a full Ubuntu Operating system.
These images have everything in one package and run across several different environments with only a few variables needed to be changed.
There are also different versions for different hardware architectures and you'll find more information and install instructions from the developer on their project pages.
Docker Compose
Docker Compose files are the final part of the ecosystem you'll need to get familiar with when using Docker.
These are YAML files with the .yml extension that contain the specific instructions needed to create the environment to run the Docker Image.
These will download the image, if you don't have it already locally so can be shared or used to run on another machine quickly. Most importantly it will run the same way every-time in a predictable, efficient way. The Docker Compose file is created using a text editor like Notepad++ in Windows or Nano/Vim in Linux.
Here's is an example of one that would spin up the docker version of Nginx Proxy Manager.
version: '3.8'
services:
app:
image: 'jc21/nginx-proxy-manager:latest'
restart: unless-stopped
ports:
# These ports are in format <host-port>:<container-port>
- '80:80' # Public HTTP Port
- '443:443' # Public HTTPS Port
- '81:81' # Admin Web Port
# Add any other Stream port you want to expose
# - '21:21' # FTP
# Uncomment the next line if you uncomment anything in the section
# environment:
# Uncomment this if you want to change the location of
# the SQLite DB file within the container
# DB_SQLITE_FILE: "/data/database.sqlite"
# Uncomment this if IPv6 is not enabled on your host
# DISABLE_IPV6: 'true'
volumes:
- ./data:/data
- ./letsencrypt:/etc/letsencrypt
You can usually find the Docker Compose file on the project page on Docker Hub or GitHub when you get an image if you're looking for more to try out.
You can also find a whole load of example Docker Compose files here for inspiration and to run once you've got the Docker Engine installed.
GitHub - docker/awesome-compose: Awesome Docker Compose samples
https://github.com/docker/awesome-compose
These are ran using the docker command below usually unless stated otherwise. This runs the container in detached mode so you can continue to use the terminal
docker-compose up -d
Docker Run
You can use a Docker Compose file or instead just a Docker Run Command to start running an application.
Here's how to run NGINX Proxy Manager using the Docker Run Command
docker run -d \
--name=nginx-proxy-manager \
--restart unless-stopped \
-p 8181:8181 \
-p 8080:8080 \
-p 4443:4443 \
-v /docker/appdata/nginx-proxy-manager:/config:rw \
jlesage/nginx-proxy-manager
If you copy and paste the above into a terminal then it will run Nginx Proxy Manager just like the Docker Compose file.
This may come in handy on systems where you can't easily navigate to the correct folder but can run Docker commands. It's also a very quick way to spin up containers for testing.
Now you've had a quick Intro to Docker, we're ready to install this to the operating system and device of your choice.
Docker Engine
To use Docker you need to install the Docker Engine on your chosen Operating system which will set up everything in the background to get things running.
Raspberry Pi (Linux)
The Raspberry Pi 4 is a powerful machine for it’s small form factor and makes the perfect candidate for experimenting with Docker.
Linux is the best overall operating system and platform for Docker in my humble opinion for performance and learning potential. I'm running Docker on a Raspberry Pi 4, Raspberry Pi 3, Raspberry Pi Zero and through a Linux VM on my Windows Desktop.
There's a simple script provided directly by Docker themselves that you can run to automate the installation process
On the flipside, it can be a bit daunting if you're unfamiliar with Linux when it comes to troubleshooting. This can be a great way to learn the OS as a whole.
We'll go over the install in a future guide in this series and it'll be linked here
Windows 11
This can also be run on Windows machine by installing Docker Desktop which give you a GUI to manage your containers.
It has a few quirks and specific ways in which the file paths work for the containers compared to Linux.
This was the way I first started using Docker. It taught me a lot of the fundamentals and being in Windows can make it easier to troubleshoot. I personally still use Docker Desktop on my own Windows Laptop for using Docker on the go.
Docker Desktop on Windows will give you the option to use WSL2 (Windows Subsystem for Linux). This is a full Linux installation running under the hood of Windows and lets you use Linux commands for Docker just like a full VM.
To get the best performance of our Docker on Windows you should get WSL2 but it's optional.
We'll go over the install in a future guide in this series and it'll be linked here
Congratulations, that's the nuts and bolts of Docker but in the rest of this series we're going to go through exactly how to install Docker on Linux (Raspberry Pi) and Windows for those of you who want to try it out.
Join us next time for Part 2a - How to Install Docker on a Raspberry Pi using Linux
Part 2a - How to Install Docker on a Raspberry Pi using Linux
Don't forget to explore the rest of our website as we build out more content. Stay tuned for more tutorials, tips, and tricks to help you make tech work for you.
Top comments (0)