How to Install Docker on Ubuntu 24.04 | Vultr Docs (2024)

Introduction

Docker is an open-source platform designed to automate application deployment, scaling, and management using containers. Containers are lightweight and portable executable packages that contain all the necessary resources required to run an application. A container includes the application code, runtime, libraries, and dependencies that ensure consistency when running the application.

This article explains how to install Docker on an Ubuntu 24.04 server, run a containerized application, and deploy it to the Vultr container registry.

Prerequisites

Before you begin:

  • Deploy an Ubuntu 24.04 server instance on Vultr.

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

  • Update the server.

  • Create a Vultr Container Registry to store your Docker images.

Install Docker

  1. Install all required dependency packages.

    console

    $ sudo apt install apt-transport-https ca-certificates curl software-properties-common -y
  2. 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
  3. 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
  4. Update the server package index.

    console

    $ sudo apt update
  5. Install Docker.

    console

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

    The above command installs the latest Docker version with the following plugins:

    • docker-ce: The Docker engine community edition package.
    • docker-ce-cli: Enables the Docker command line interface (CLI).
    • containerd.io: A container runtime that monitors the lifecycle of Docker containers.
    • docker-buildx-plugin: Improves Docker's image-building capabilities for multi-platform builds.
    • docker-compose-plugin: Enables the management of multi-container Docker applications using YAML files.
  6. View the installed Docker version on your server.

    console

    $ sudo docker --version

    Output:

    Docker version 26.1.4, build 5650f9b

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 (/usr/lib/systemd/system/docker.service; enabled; preset: enabled) Active: active (running) since Mon 2024-06-17 21:07:25 UTC; 1min 2s agoTriggeredBy: ● docker.socket Docs: https://docs.docker.com Main PID: 120312 (dockerd) Tasks: 8 Memory: 34.5M (peak: 35.3M) CPU: 281ms CGroup: /system.slice/docker.service └─120312 /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 runs containerized applications using local or remote container images from registries such as Docker Hub. Follow the steps below to run a sample Nginx containerized application to test Docker on your server.

  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.

    $ sudo docker images

    Output:

    REPOSITORY TAG IMAGE ID CREATED SIZEnginx 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 above command runs a new Docker container on the server using your Nginx image with the following values:

    • -name mynginx: Sets the container name to mynginx.
    • d: Starts the container in detached mode as a background process on the server.
    • p 80:80: Maps the host port 80 to the container port 80. This allows you to access the conatiner using the host port on your server.
    • nginx:latest: Sets the Docker image to use when creating the container.
  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 NAMESd79cad9ea8d2 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

    How to Install Docker on Ubuntu 24.04 | Vultr Docs (1)

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 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.

    $ sudo docker images

    Output:

    REPOSITORY TAG IMAGE ID CREATED SIZEnginx latest dde0cca083bc 2 weeks ago 188MBsjc.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.

    How to Install Docker on Ubuntu 24.04 | Vultr Docs (2)

  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

You have installed Docker on Ubuntu 24.04, run a containerized application, and deployed local container images to the Vultr Container Registry. You can run multiple Docker images on your server and securely access them on your server without accessing the container environment directly. For more information, visit the Docker reference documentation.

How to Install Docker on Ubuntu 24.04 | Vultr Docs (2024)
Top Articles
Latest Posts
Article information

Author: Ray Christiansen

Last Updated:

Views: 5923

Rating: 4.9 / 5 (69 voted)

Reviews: 92% of readers found this page helpful

Author information

Name: Ray Christiansen

Birthday: 1998-05-04

Address: Apt. 814 34339 Sauer Islands, Hirtheville, GA 02446-8771

Phone: +337636892828

Job: Lead Hospitality Designer

Hobby: Urban exploration, Tai chi, Lockpicking, Fashion, Gunsmithing, Pottery, Geocaching

Introduction: My name is Ray Christiansen, I am a fair, good, cute, gentle, vast, glamorous, excited person who loves writing and wants to share my knowledge and understanding with you.