Installing Docker – Containerization with Docker

We will be installing Docker in an Ubuntu system. For other OSs, please refer to https://docs.

docker.com/engine/install/.

To install Docker, we need to install supporting tools to allow the apt package manager to download

Docker through HTTPS. Let’s do so using the following commands:

$ sudo apt-get update

$ sudo apt-get install -y ca-certificates curl gnupg

Download the Docker gpg key and add it to the apt package manager:

$ sudo install -m 0755 -d /etc/apt/keyrings

$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | \ sudo gpg –dearmor -o /etc/apt/keyrings/docker.gpg $ sudo chmod a+r /etc/apt/keyrings/docker.gpg

Then, you need to add the Docker repository to your apt configuration so that you can download packages from there:

$ echo \

“deb

[arch=”$(dpkg –print-architecture)” \

 

signed-by=/etc/apt/keyrings/docker.gpg]

\

https://download.docker.com/linux/ubuntu \

“$(. /etc/os-release && echo “$VERSION_CODENAME”)” \ stable” | sudo tee /etc/apt/sources.list.d/docker.list \ > /dev/null

Finally, install the Docker engine by using the following commands:

$ sudo apt-get update

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

To verify whether Docker has been installed successfully, run the following:

$ sudo docker –version

You should expect a similar output to the following:

Docker version 24.0.2, build cb74dfc

The next thing you should do is allow regular users to use Docker. You want your users to act as something other than root for building and running containers. To do that, run the following command:

$ sudo usermod -a -G docker <username>

To apply the changes to your profile, log out from your virtual machine and log back in.

Now that Docker has been fully set up on your machine, let’s run a hello-world container to see this for ourselves:

$ docker run hello-world

You should see the following output:

Unable to find image ‘hello-world:latest’ locally

latest: Pulling from library/hello-world

719385e32844: Pull complete

Digest: sha256:fc6cf906cbfa013e80938cdf0bb199fbdbb86d6e3e013783e5a766f50f5dbce0

Status: Downloaded newer image for hello-world:latest Hello from Docker!

You will also receive the following message, which tells you what happened behind the scenes to print the Hello from Docker! message on your screen:

This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:

  1. The Docker client contacted the Docker daemon.
  2. The Docker daemon pulled the hello-world image from Docker Hub.(amd64).
  3. The Docker daemon created a new container from that image that runs the executable that produces the output you are currently reading.
  4. The Docker daemon streamed that output to the Docker client, which sent it to your Terminal:

To try something more ambitious, you can run an Ubuntu container with: $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID: https://hub.docker.com/

For more examples and ideas, visit: https://docs.docker.com/get-started/

All this helpful information is self -explanatory. To explain Docker Hub a bit, it is a public Docker container registry that hosts many Docker images for people like you and me to consume.

As Docker works on a layered architecture, most Docker images are derived from one or more base images hosted on Docker Hub. So, please create a Docker Hub account for yourself to host your containers and share them with the rest of the world.

Most organizations might want to keep their images private, so you have the option of creating private repositories within Docker Hub. You can also host your own internal Docker registry using a SaaS service such as Google Container Registry ( GCR), or installing an artifact repository such as Sonatype Nexus or JFrog Artifactory. Whatever your choice of tool, the mechanism and how it works always remain the same.

Leave a Reply

Your email address will not be published. Required fields are marked *