How to Install Docker on Ubuntu

As you may know, Docker allows you to pack, ship and run any application as a lightweight container. It’s like a virtual machine, only more portable and resources-efficient. This tutorial is going to show you how to install Docker on Ubuntu.

Requirements of Installing Docker on Ubuntu

You must be using a 64 bits OS because Docker doesn’t support 32 bits.

Install Docker from Ubuntu Repository

Docker is included in Ubuntu software repository. We can install the Docker runtime by executing the following command in terminal. This works on any current Ubuntu versions, including Ubuntu 16.04, Ubuntu 18.04, Ubuntu 19.10, Ubuntu 20.04.

sudo apt install docker.io

install docker on ubuntu from ubuntu repository

During the installation, a docker group and a Systemd service will be created. You can check the systemd service with:

systemctl status containerd

Sample output:

 containerd.service - containerd container runtime
     Loaded: loaded (/lib/systemd/system/containerd.service; enabled; vendor preset: enabled)
     Active: active (running) since Tue 2020-04-21 09:32:38 HKT; 1min 45s ago
       Docs: https://containerd.io
   Main PID: 2035184 (containerd)
      Tasks: 11
     Memory: 22.2M
     CGroup: /system.slice/containerd.service
             └─2035184 /usr/bin/containerd

Install Docker on Ubuntu from Docker’s APT Repository

The upstream Docker repository currently supports Ubuntu 16.04, Ubuntu 18.04 and Ubuntu 19.10.

To ensure that we have the latest and greatest version, we will have to install it from Docker’s APT repository. Run the following command to add Docker repository to your Ubuntu system.

echo "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list

Next, run the following command to import the Docker GPG key to Ubuntu system so that APT can verify package integrity during installation.

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

And because this repository uses HTTPS connection, which I recommend all software repositories should be using, we also need to install apt-transport-https and ca-certificates package.

sudo apt install apt-transport-https ca-certificates

Finally, update the package index on your Ubuntu system and install docker-ce (Docker Community Edition).

sudo apt update

sudo apt install docker-ce

Some Simple Commands You May Want to Run After Installing Docker

Once Docker is installed, the Docker daemon should be automatically started. You can check its status with:

systemctl status docker

systemctl status docker

If it’s not running, then start the daemon with this command:

sudo systemctl start docker

And enable autostart at boot time:

sudo systemctl enable docker

Check Docker version.

docker -v

Sample output:

Docker version 19.03.8, build afacb8b7f0

Display system-wide information regarding the Docker installation.

sudo docker info

Output:

Client:
Debug Mode: false

Server:
Containers: 0
Running: 0
Paused: 0
Stopped: 0
Images: 0
Server Version: 19.03.8
Storage Driver: overlay2
Backing Filesystem: <unknown>
Supports d_type: true
Native Overlay Diff: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
Volume: local
Network: bridge host ipvlan macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version:
runc version:
init version:
Security Options:
apparmor
seccomp
Profile: default
Kernel Version: 5.4.0-21-generic
Operating System: Ubuntu 20.04 LTS
OSType: linux
Architecture: x86_64
CPUs: 2
Total Memory: 7.776GiB
Name: focal
ID: 6WTB:ZCUU:BBET:XA2C:7OAP:WPWZ:N5OR:CFD6:Z32V:GJWE:D5VW:PYEG
Docker Root Dir: /var/lib/docker
Debug Mode: false
Registry: https://index.docker.io/v1/
Labels:
Experimental: false
Insecure Registries:
127.0.0.0/8
Live Restore Enabled: false

WARNING: No swap limit support

Verify Docker is installed correctly.

sudo docker run hello-world

You should see the following message indicating that Docker is working correctly.

Hello from Docker!
This message shows that your installation appears to be working correctly.

sudo docker run hello-world

Wrapping Up

I hope this tutorial helped you install Docker on Ubuntu. As always, if you found this post useful, then subscribe to our free newsletter.

Rate this tutorial
[Total: 31 Average: 4.8]

One Response to “How to Install Docker on Ubuntu

  • crazyredneck
    2 years ago

    Accurate, easy to follow tutorial. Thanks for putting this together!

Leave a Comment

  • Comments with links are moderated by admin before published.
  • Your email address will not be published.
  • Use <pre> ... </pre> HTML tag to quote the output from your terminal/console.
  • Please use the community (https://community.linuxbabe.com) for questions unrelated to this article.
  • I don't have time to answer every question. Making a donation would incentivize me to spend more time answering questions.


The maximum upload file size: 2 MB.
You can upload: image.