tutorials
Installing Docker on Ubuntu
Overview
This tutorial provides instructions for installing Docker on Ubuntu. While the steps outlined here may work for other versions of Ubuntu (and some non-Ubuntu Linux distributions), these instructions were tested against Ubuntu 24.04 LTS.
Outcomes
- A working
dockerinstallation
Prerequisites
Before starting this tutorial, ensure that …
- You have a working Ubuntu LTS installation
- You are comfortable with the basics of the Linux command line
- are familiar with containerization
Background
Docker is both a software company and a popular software implementation of containerization. We'll be using it throughout this course to run examples and assignments.
Installation
The Docker engine can be installed on MacOS, Linux, and even Windows* (with some caveats). This tutorial provides instructions for installing Docker on the latest Ubuntu LTS using the command line.
MacOS
If you would like to install on MacOS (Docker Desktop), follow the official installation instructions:
Note, however, that there are numerous things you will need to configure.
Windows (not recommended)
At the time of this writing, I do not recommend installing Docker Desktop on Windows. I recommend that Windows users instead install docker in a Linux virtual machine.
Ubuntu (recommended)
We'll use the linux CLI to install Docker on Ubuntu. From your terminal, …
Step 1: Update your system
Before install docker, let's update our package index:
sudo apt-get -y update
Step 3: Install docker and docker-compose
We'll install the community edition of Docker (the docker-ce package) along with a tool for orchestrating several containerized services.
Follow the official Docker installation instructions for Ubuntu: https://docs.docker.com/engine/install/ubuntu/
Step 4 (Optional): Configure Docker to run without sudo
Running docker requires adminstrative privileges. Theses privileges are invoked by using the sudo commmand. To avoid needing to type this
#sudo groupadd docker
sudo usermod -aG docker $USER
# avoid the need to restart to apply changes
newgrp docker
You can learn more about this step here.
Testing your installation
To test our installation, we'll pull (download) the hello-world image from DockerHub and launch a container using that image:
docker run hello-world:latest
👀 If you get a permission error, run the command with sudo (i.e., sudo docker run hello-world:latest).
By convention, the :latest tag should reference the most recent version of the image.
You should see output like the following:
Hello from Docker!
This message shows that your installation appears to be working correctly.
To generate this message, Docker took the following steps:
1. The Docker client contacted the Docker daemon.
2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
(amd64)
3. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
4. The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.
To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash
Share images, automate workflows, and more with a free Docker ID:
https://hub.docker.com/
For more examples and ideas, visit:
https://docs.docker.com/get-started/
Congrats! You're ready to run containerized apps!