How to Install Docker on Ubuntu 20.04

Updated on 07 May, 2025
How to Install Docker on Ubuntu 20.04 header image

Docker is an open-source platform that simplifies deploying, scaling, and managing applications using containers. Containers are lightweight, portable units that package an application with its code, runtime, libraries, and dependencies, ensuring it runs consistently across environments.

This article shows you how to install Docker on Ubuntu 20.04, run a containerized app, and deploy it to the Vultr Container Registry.

Warning
Vultr Cloud GPU instances running Ubuntu come with Docker as a pre-installed feature. Attempting to install Docker on these servers may result in conflicts with the NVIDIA Container Toolkit, potentially impacting GPU performance and container compatibility.

Prerequisites

Before you begin:

  • Have an Ubuntu 20.04 server.

  • Access the server using SSH as a non-root user with sudo privileges.

  • Update the server.

  • Create a Container Registry to store your Docker images. This article uses Vultr Container Registry as an example, but the commands can be adapted to any registry by switching to the appropriate registry-specific variables.

Install Docker

  1. Update the server package index.

    console
    $ sudo apt update
    
  2. Install all required dependency packages.

    console
    $ sudo apt install apt-transport-https ca-certificates curl software-properties-common -y
    
  3. Create the keyring directory.

    console
    $ sudo mkdir -p /etc/apt/keyrings
    
  4. Add the Docker GPG key to your server's keyring.

    console
    $ sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
    
  5. Add the latest Docker repository to your APT sources.

    console
    $ echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
    
  6. Update the server package index.

    console
    $ sudo apt update
    
  7. Install Docker.

    console
    $ sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
    

    The command above installs Docker along with several key components:

    • docker-ce: The core Docker Engine (Community Edition).
    • docker-ce-cli: Provides the Docker command-line interface.
    • containerd.io: Handles the container runtime and lifecycle management.
    • docker-buildx-plugin: Extends Docker’s build functionality for cross-platform image builds.
    • docker-compose-plugin: Supports defining and managing multi-container applications using Compose YAML files.
  8. View the installed Docker version on your server.

    console
    $ sudo docker --version
    

    Output:

    Docker version 28.0.4, build b8034c0

Manage the Docker System Service

  1. Enable the Docker system service to start automatically at boot time.

    console
    $ sudo systemctl enable docker
    
  2. View the Docker service status and verify that it's running.

    console
    $ sudo systemctl status docker
    

    Output:

    ● docker.service - Docker Application Container Engine
         Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
         Active: active (running) since Sat 2025-04-05 19:55:43 UTC; 2min 32s ago
    TriggeredBy: ● docker.socket
           Docs: https://docs.docker.com
       Main PID: 4205 (dockerd)
          Tasks: 10
         Memory: 22.3M
         CGroup: /system.slice/docker.service
                 └─4205 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
  3. Run the following command to stop Docker.

    console
    $ sudo systemctl stop docker
    
  4. Restart the Docker service.

    console
    $ sudo systemctl restart docker
    

Run a Containerized Application

Docker uses container images—either stored locally or pulled from registries like Docker Hub—to run applications. Use the steps below to launch a sample Nginx container to verify your Docker installation.

  1. Pull the latest Nginx image from Docker Hub.

    console
    $ sudo docker pull nginx:latest
    
  2. View all Docker images on the server and verify that the Nginx image is available.

    console
    $ sudo docker images
    

    Output:

    REPOSITORY   TAG       IMAGE ID       CREATED       SIZE
    nginx        latest    dde0cca083bc   2 weeks ago   188MB
  3. Run a new Docker container using the image.

    console
    $ sudo docker run --name mynginx -d -p 80:80 nginx:latest
    

    The command above starts a Docker container running the Nginx image with the following options:

    • --name mynginx: Assigns the name mynginx to the container.
    • -d: Runs the container in detached mode, allowing it to operate in the background.
    • -p 80:80: Forwards traffic from port 80 on the host to port 80 in the container, making the Nginx server accessible via the host IP.
    • nginx:latest: Specifies the latest version of the official Nginx image as the container base.
  4. List all the running containers on the server and verify that the new container is up.

    console
    $ sudo docker ps
    

    Output:

    CONTAINER ID   IMAGE          COMMAND                  CREATED         STATUS         PORTS                               NAMES
    d79cad9ea8d2   nginx:latest   "/docker-entrypoint.…"   5 seconds ago   Up 4 seconds   0.0.0.0:80->80/tcp, :::80->80/tcp   mynewnginx
  5. Allow the HTTP port 80 through the firewall to enable connections to the port.

    console
    $ sudo ufw allow 80/tcp
    
  6. Access your server IP address using a web browser such as Chrome to test access to the Docker container.

    http://SERVER-IP

    Access the Nginx Docker Container Application

Deploy a Containerized Application to Vultr Container Registry

Docker supports public and private registries to build and deploy container images on your server. The Vultr Container Registry allows you to build Docker images, manage multiple versions, and distribute the images to different environments. Follow the steps below to tag and deploy your local Nginx image to the Vultr Container Registry using Docker.

  1. Open the Vultr customer portal.

  2. Access your Vultr Container Registry management panel and note the credentials to use when accessing the registry.

  3. Access your server terminal session and run the following Docker command to login to the Vultr container registry. Replace https://sjc.vultrcr.com/samplecontainerregistry, example-user and apikey1234 with your actual registry details.

    console
    $ sudo docker login https://sjc.vultrcr.com/samplecontainerregistry -u example-user -p apikey1234
    
  4. Tag your Nginx Docker image with your Vultr Container Registry.

    console
    $ sudo docker tag nginx:latest  sjc.vultrcr.com/samplecontainerregistry/mynginx:latest
    
  5. View all Docker images on the server and verify that the new image is available.

    console
    $ sudo docker images
    

    Output:

    REPOSITORY                                              TAG       IMAGE ID       CREATED       SIZE
    nginx                                                   latest    dde0cca083bc   2 weeks ago   188MB
    sjc.vultrcr.com/samplecontainerregistry/mynginx         latest    dde0cca083bc   2 weeks ago   188MB    
  6. Push the tagged image to your Vultr container registry.

    console
    $ sudo docker push sjc.vultrcr.com/samplecontainerregistry/mynginx:latest
    
  7. Access your Vultr Container Registry management panel.

  8. Navigate to the Repositories tab and verify that the new Docker image is available.

    Vultr Container Registry Repository

  9. Run the following command to pull the image from the Vultr Container Registry.

    console
    $ sudo docker pull sjc.vultrcr.com/samplecontainerregistry/mynginx:latest
    

Conclusion

Docker is now installed on your Ubuntu 20.04 server. You've successfully launched a containerized application and pushed local images to the Vultr Container Registry. You can run multiple Docker containers simultaneously and access them securely without needing to enter the container environments.

Comments

No comments yet.