In Part 1 of this series, I gave a very brief overview of Docker and discussed how I use it at home for non-production purposes. In this post, I'll cover the basic Docker installation steps that I use.
The Fun with Docker Series
Links to the entire series are here:
- Part 1 - Docker - An introduction
- Part 2a - Getting started with Docker (this post)
- Part 2b - More getting started with Docker
- Part 3 - Docker Compose
- Part 4 - Docker Volumes (and Bind Mounts)
- Part 5 - Docker Networking
- Part 6 - Monitoring your Docker setup with Portainer
- Part 7 - Setting up this blog with Let's Encrypt, Nginx, and Ghost
There are a million-and-one pages out there describing how to install Docker, and probably a million-and-two different ways to do it. This is the method that I've used recently and I'm mostly documenting this for my own purposes so that I can come back to it the next time I need to install without needing to Google and sort through the million-and-one results to find the one I'm looking for.
Note: We're going to be installing Docker Community Edition (Docker CE) rather than the Enterprise Edition, as this is all we need for a non-production or smaller implementation.
The first thing we need to do is update our package lists in Ubuntu/Raspbian:
sudo apt update
Next, we'll install some tools that will allow
apt to function over HTTPS - These may already exist on your host, but it won't hurt to make sure regardless:
sudo apt install apt-transport-https ca-certificates curl software-properties-common
We should remove any older versions of Docker, especially the non-CE versions:
sudo apt remove docker docker-engine docker.io
Add the GPG key for the official Docker repository to
curl -fsSL https://download.docker.com/linux/$(. /etc/os-release; echo "$ID")/gpg | sudo apt-key add -
Add the Docker repository to your
On Raspberry Pi:
echo "deb [arch=armhf] https://download.docker.com/linux/$(. /etc/os-release; echo "$ID") $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
apt package database with the packages from the new Docker repository that you just added.
sudo apt update
Finally, we'll install latest version of Docker CE from the official Docker repository.
sudo apt install docker-ce
Optional (but strongly suggested) - If you want to be able to run Docker commands as the current user instead of using sudo, run this command:
sudo usermod -aG docker $USER
And that's it! Docker should now be installed on your Ubuntu or Raspberry Pi system. Now for some verification.
Verifying your new Docker install
Note: If you didn't use the
usermodcommand above, you'll have to add sudo to the rest of these commands.
The first command we'll use for testing is simply :
This command is used to list any containers running on your system (similar to the Linux
ps command) along with some details. If everything above went smoothly, it should run but not display any containers.
Here's the output (with some terrible line-wrapping) from the system that this blog is running on.
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 8a3d8d5701f6 ghost:latest "docker-entrypoint.s…" 46 hours ago Up 31 hours 2368/tcp docker_ghost_1 5661f9a6eddc linuxserver/letsencrypt "/init" 46 hours ago Up 46 hours 0.0.0.0:80->80/tcp, 0.0.0.0:443->443/tcp letsencrypt
Spoiler Alert: This blog and the webserver in front of it are running wholly in the above containers. Setting these up is actually what inspired me to start the blog. I'll cover them in a future post.
As I got deep into writing this post, I realized that it had become way too long, so I decided to split it into two parts. The next part can be found here, where we'll spin up our first containers and review some basic Docker commands.