ByteNAP Networks Private Limited

ByteNAP Networks Color

Overview Of Installing and How to Use Docker on Ubuntu in Linux VPS Server

Docker serves as an open-source platform tailored for the development, transportation, and execution of applications on Ubuntu OS in Linux VPS Server. Its primary objective is to simplify the process of creating, deploying, and running applications through the utilization of containers. By leveraging Docker, developers can encapsulate their applications into standardized units known as containers, enabling them to run seamlessly on any computer, regardless of the underlying operating system or hardware.

The platform facilitates the rapid and straightforward deployment of applications within a uniform environment, alleviating concerns about the intricacies of the infrastructure. Docker also offers an extensive array of tools and services for effectively managing and monitoring applications. Additionally, it provides features for constructing and sharing images collaboratively among developers. Recognized as an indispensable tool in modern software development, Docker is widely adopted by some of the world’s leading companies.

This tutorial guides you through the installation and utilization of Docker Community Edition (CE) on Ubuntu 22.04 in Linux VPS Server.

Requirements

Familiarity with the Linux command line is essential. You need an Ubuntu 22.04 Linux VPS Server with a non-root user possessing sudo privileges. You can acquire an affordable and potent Ubuntu Linux VPS Server from our website. Refer to our “How to access your server using SSH” guide for instructions on accessing your server and establishing a sudo user.

Updating Package Cache and Installing Necessary Packages

Start by updating the packages in the package manager cache to the latest available versions using the following command:

 sudo apt update

Next, install a few packages that will allow us to use apt with HTTPS in order to add the official docker repository and get the latest version of Docker. To do this, run the following command:

sudo apt -y install apt-transport-https ca-certificates curl software-properties-common

Installing Docker

We will use the official Docker repository to install the latest version of Docker. First, add the GPG key for the official Docker repository to your system:

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg

Next, add the official Docker repository to your APT sources:

echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

Update your package index:

sudo apt update

Now, with the repository added, install the docker-ce package, which is the Docker Community Edition package:

sudo apt install docker-ce

Once the installation finishes, check that Docker is running:

sudo systemctl status docker

You should receive output indicating that Docker is active and running, similar to the following:

  • docker.service – Docker Application Container Engine
Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
     Active: active (running) since Sun 2022-12-18 13:50:49 UTC; 32s ago
TriggeredBy: ● docker.socket
       Docs: https://docs.docker.com
   Main PID: 323716 (dockerd)
      Tasks: 9
     Memory: 24.4M
        CPU: 429ms
     CGroup: /system.slice/docker.service
             └─323716 /usr/bin/dockerd -H fd://-containerd=/run/containerd/containerd.sock

Using Docker

With docker installed, you can now use it to manage Docker images.

To see all available docker subcommands, run the following command:

docker

You should receive a list of docker subcommands and a brief description for each one.

You can use the syntax docker COMMAND –help to get more information on a specific subcommand. For example, to get more information on the docker rm command, you can use the –help flag as follows:

docker rm --help

You should receive output similar to the following:

Usage:  docker rm [OPTIONS] CONTAINER [CONTAINER...]

Remove one or more containers

Options:

 -f, --force     Force the removal of a running container (uses SIGKILL)
  -l, --link      Remove the specified link
  -v, --volumes   Remove anonymous volumes associated with the container

To view general information on your Docker installation, use docker info like so:

sudo docker info

This will show you information on your Docker configuration and Linux VPS Server properties.

Downloading a Docker Image from Docker Hub:

It is a cloud-based service that provides a centralized repository for Docker images. It allows users to store, manage, and share Docker images with other users. It provides a secure and reliable way to share and store Docker images, which can be used to create and deploy applications. Docker Hub also provides a wide range of services, such as private repositories, automated builds, and integration with other services.

To test whether you can access Docker Hub, run the hello-world image:

sudo docker run hello-world

You should receive an output that shows that your installation is working correctly:

Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
2db29710123e: Pull complete 
Digest: sha256:c77be1d3a47d0caf71a82dd893ee61ce01f32fc758031a6ec4cf1389248bb833Status: Downloaded newer image for hello-world:latest

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

You can use the docker search command to search for images hosted on Docker Hub like so:

sudo docker search ubuntu

Here, you search for the Linux VPS Server Ubuntu image. You should see a list of results like so:

NAME                             DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
ubuntu                           Ubuntu is a Debian-based Linux operating sys…   15357     [OK]       
websphere-liberty                WebSphere Liberty multi-architecture images …   290       [OK]       
ubuntu-upstart                   DEPRECATED, as is Upstart (find other proces…   112       [OK]       
neurodebian                      NeuroDebian provides neuroscience research s…   97        [OK]       
ubuntu/nginx                     Nginx, a high-performance reverse proxy & we…   71                   

Images that are officially maintained and supported are labeled as [OK] under the OFFICIAL column.

In the results above, you see that ubuntu is the name of the official Ubuntu image. You can download it using the docker pull command like so:

sudo docker pull ubuntu                   

You should receive the following output:

Using default tag: latest
latest: Pulling from library/ubuntu
6e3729cf69e0: Pull complete 
Digest: sha256:sha256:27cb6e6ccef575a4698b66f5de06c7ecd61589132d5a91d098f7f3f9285415a9
Status: Downloaded newer image for ubuntu:latest
docker.io/library/ubuntu:latest              

You can list the images you’ve downloaded so far using the following command:

sudo docker images

You should see ubuntu and hello-world like so:

REPOSITORY    TAG       IMAGE ID       CREATED         SIZE
ubuntu        latest    6b7dfa7e8fdb   9 days ago      77.8MB
hello-world   latest    feb5d9fea6a5   15 months ago   13.3kB

The reason the image hello-world was downloaded, is that the docker run command either runs a container using an image if it has been downloaded, or downloads the image and then runs a container using it.

Running a Docker Container:

Docker containers can be run to perform a task in an isolated environment, just like running the hello-world container performs the task of printing a message. However, containers can also be interactive.

For example, you can run a container using the Ubuntu image you’ve downloaded previously with an interactive shell using the docker run, and then -it switches:

sudo docker run -it ubuntu

Your prompt should now be a root shell like so:

root@242d22e1d9da:/#

This is the root user of your Linux VPS Server Ubuntu container, and you can now manage it just like a virtual machine.

With this shell prompt, you can run any command inside your Ubuntu container. For example, you can update the package index inside the container using apt update like so:

root@242d22e1d9da:/# apt update

You can also install any application or package using apt install. For example, you can install Python 3 like so:

root@242d22e1d9da:/# apt install python3

Once the installation finishes, you can run Python like so:

root@242d22e1d9da:/# python3

This should allow you to access the Python REPL inside your Ubuntu container:

Python 3.10.6 (main, Nov 14 2022, 16:10:14) [GCC 11.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>

With this, you can run programs and modify your container in an environment that is isolated from the rest of your Linux VPS Server.

Congratulations!

You’ve successfully installed Docker on your system and acquired the skills to explore Docker images in the official Docker Hub, download an image, and utilize it for a container. Additionally, you’ve gained knowledge on running the container’s shell, managing its packages, and installing programs. For more in-depth information on Docker, refer to the Docker guides.

 

Social Media

Stay Informed For Online World & Business Updates!

Reach us on WhatsApp
1

Hosting

Linux Hosting

Secure and Scalable Linux Hosting Solutions for Indian business

Windows Hosting

Flexible Windows Hosting for Smooth Performance

WordPress Hosting

Effortless WordPress Hosting for Superior Performance

Linux Reseller Hosting

Grow your Hosting Business with Linux Reseller Hosting

Windows Reseller Hosting

Reliable Hosting Solutions for Windows Resellers

Linux VPS Hosting

Unleash the Power of Root Access with Linux VPS Hosting

Windows VPS Hosting

Online Website Presence with Windows VPS Hosting

Indian Dedicated Server

Indian Dedicated Server: Accelerate your Indian Business

GPU Server

Upgrade to GPU servers for unbeatable high-performance computing

Clearance Dedicated Server

Take full Control: Clearance Dedicated Servers for your Business

Email

Google Workspace

Empower your Business Tools: Workflows made simple with Google Workspace

Business Email

Enhance your Professional Email Solutions: Get Custom Business Email

Security

SSL Certificate

Trustworthy Encryption for your Website with Secure SSL Certificate

Acronis Backup

Effortless, reliable data protection with seamless integration for ultimate security

BitNinja

Robust server security, defending against online threats with precision and ease

Domain

Domain Name Search

Your Online Presence Starts Here: Search for the Right Domain

Domain Transfer

Transfer your Domain with Confidence and Unlock New Opportunities

Bulk Domain Search

Multiply your Options: Explore Perfect Domain in Bulk