
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.
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.
Before you begin:
Have an Ubuntu 20.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.
Update the server package index.
Install all required dependency packages.
Create the keyring directory.
Add the Docker GPG key to your server's keyring.
Add the latest Docker repository to your APT sources.
Update the server package index.
Install Docker.
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.View the installed Docker version on your server.
Output:
Enable the Docker system service to start automatically at boot time.
View the Docker service status and verify that it's running.
Output:
Run the following command to stop Docker.
Restart the Docker service.
Add your non-root user to the Docker group to run Docker CLI commands without sudo privileges. Replace linuxuser with your actual username.
Enable the new user group changes in your active session.
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.
Pull the latest Nginx image from Docker Hub.
View all Docker images on the server and verify that the Nginx image is available.
Output:
Run a new Docker container using the image.
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.List all the running containers on the server and verify that the new container is up.
Output:
Allow the HTTP port 80 through the firewall to enable connections to the port.
Access your server IP address using a web browser such as Chrome to test access to the Docker container.
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 Console.
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 and apikey1234 with your actual registry details.
Tag your Nginx Docker image with your Vultr Container Registry.
View all Docker images on the server and verify that the new image is available.
Output:
Push the tagged image to your Vultr container registry.
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.
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.
0 Comments
Be the first to comment and share your perspective with the community.