
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.
In this article, you are to install Docker on an Ubuntu 22.04 server, run a containerized application, and deploy it to a container registry
Prerequisites
Before you begin:
Have an Ubuntu 22.04 server.
Access the server using SSH as a non-root user with sudo privileges.
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
Update the server package index.
console$ sudo apt update
Install all required dependency packages.
console$ sudo apt install apt-transport-https ca-certificates curl software-properties-common -y
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
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
Update the server package index.
console$ sudo apt update
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
: Docker Engine Community Edition.docker-ce-cli
: Provides the Docker command line interface (CLI).containerd.io
: Container runtime for managing Docker container lifecycles.docker-buildx-plugin
: Enhances Docker's image-building for multi-platform support.docker-compose-plugin
: Manages multi-container Docker applications using YAML files.
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
Enable the system service to start automatically at boot time.
console$ sudo systemctl enable docker
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
Run the following command to stop the Docker service.
console$ sudo systemctl stop docker
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.
Pull the latest Nginx image from Docker Hub.
console$ sudo docker pull nginx:latest
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
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 tomynginx
.-d
: Runs the container in detached mode, as a background process.-p 80:80
: Maps the host port80
to the container port80
, allowing access via the host port.nginx:latest
: Specifies the Docker image to use for the container.
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
Allow the HTTP port
80
through the firewall to enable connections to the port.console$ sudo ufw allow 80/tcp
Access your server IP address using a web browser such as Chrome to test access to the Docker container.
http://SERVER-IP
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.
Open the Vultr customer portal.
Access your Vultr Container Registry management panel and note the credentials to use when accessing the registry.
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
andapikey1234
with your actual registry details.console$ sudo docker login https://sjc.vultrcr.com/samplecontainerregistry -u example-user -p apikey1234
Tag your Nginx Docker image with your Vultr Container Registry.
console$ sudo docker tag nginx:latest sjc.vultrcr.com/samplecontainerregistry/mynginx:latest
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
Push the tagged image to your Vultr container registry.
console$ sudo docker push sjc.vultrcr.com/samplecontainerregistry/mynginx:latest
Access your Vultr Container Registry management panel.
Navigate to the Repositories tab and verify that the new Docker image is available.
Run the following command to pull the image from the Vultr Container Registry.
console$ sudo docker pull sjc.vultrcr.com/samplecontainerregistry/mynginx:latest
Conclusion
In this article, you installed Docker on Ubuntu 22.04, ran a containerized application, and deployed local images to the Vultr Container Registry. You can run multiple Docker images on your server and securely access them without directly interacting with the container environment.For more information, visit the Docker reference documentation.
No comments yet.