Hello World Docker

Meghal Chhabria
5 min readDec 9, 2020

--

Though I’m a bit late, but never the less let’s hope for the best :)

What is Docker?

Docker Ecosystem Source: Udemy

Docker is open-source platform which packages software into independent containers which makes it easy to port anywhere. Technical enough right?

According to a layman, diving the functionality of your software into individual blocks is called as containerization.

Hence this mechanism is provided by Docker. :)

How to use it?

Install docker engine from https://docs.docker.com/engine/install/ based on your OS. Alternatively you can also run your OS on Windows 10 with it’s latest Windows Subsystem for Linux also called as WSL (will write a short blog on this soon).

Again started worrying?

What is WSL?

WSL allows you to run linux distributions on windows with installing a virtualization software.

Fun fact → this is containerization :D

Excited?

Let’s start.

I installed on ubuntu distribution on WSL.

Incase you are installing on other distribution, please read the documentation on docker https://docs.docker.com/engine/install/ which is very straightforward and easy to follow.

In ubuntu,

  1. Update apt package and allow to download packages over http.
sudo apt-get updatesudo apt-get install \
apt-transport-https \
ca-certificates \
curl \
gnupg-agent \
software-properties-common
OutputHit:1 http://archive.ubuntu.com/ubuntu focal InRelease
Hit:2 http://archive.ubuntu.com/ubuntu focal-updates InRelease
Hit:3 https://download.docker.com/linux/ubuntu focal InRelease
Hit:4 http://security.ubuntu.com/ubuntu focal-security InRelease
Hit:5 http://archive.ubuntu.com/ubuntu focal-backports InRelease
Reading package lists... Done

2. Add Docker to GPG ( it’s a technique for code signing for linux code repositores ). In simple words, it authenticates docker repositories for our use.

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -Output
OK

3. Once you are added, verification is also important. Hence to verify that we got the key with fingerprint9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88 , search for last 8 chars.

sudo apt-key fingerprint 0EBFCD88Output
pub rsa4096 2017-02-22 [SCEA]
9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88
uid [ unknown] Docker Release (CE deb) <docker@docker.com>
sub rsa4096 2017-02-22 [S]

4. To get a stable releases of software , run this command,

sudo add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) \
stable"

In case you want to get the nightly releases or test release replace the option in the command.

where as, lsb_release -cs gives the dubbed name of your linux distribution i.e. ubuntu in my case.

lsb_release -cs
focal (Ubuntu
20.04 LTS)

5. All the above were pre-requisites for installing docker engine, once that is done. Hit this command and you are good to go.

$ sudo apt-get update
$ sudo apt-get install docker-ce docker-ce-cli containerd.io

Note: this will install the latest stable version of docker for your distribution.

To install a specific version of Docker engine , list all version available in our repository

$ apt-cache madison docker-ce
docker-ce | 5:20.10.0~3-0~ubuntu-focal | https://download.docker.com/linux/ubuntu focal/stable amd64 Packages
docker-ce |
5:19.03.14~3-0~ubuntu-focal | https://download.docker.com/linux/ubuntu focal/stable amd64 Packages
docker-ce |
5:19.03.13~3-0~ubuntu-focal | https://download.docker.com/linux/ubuntu focal/stable amd64 Packages
docker-ce |
5:19.03.12~3-0~ubuntu-focal | https://download.docker.com/linux/ubuntu focal/stable amd64 Packages
docker-ce |
5:19.03.11~3-0~ubuntu-focal | https://download.docker.com/linux/ubuntu focal/stable amd64 Packages
docker-ce |
5:19.03.10~3-0~ubuntu-focal | https://download.docker.com/linux/ubuntu focal/stable amd64 Packages
docker-ce |
5:19.03.9~3-0~ubuntu-focal | https://download.docker.com/linux/ubuntu focal/stable amd64 Packages

Select a version, and install using the following command

Note: the version string will be the highlighted value in above output for example → 5:20.10.0~3–0~ubuntu-focal

sudo apt-get install docker-ce=<VERSION_STRING> docker-ce-cli=<VERSION_STRING> containerd.io

Congrats , you installed it successfully :D. Wasn’t that easy? Of course yes!!!

Now check if docker is running or not

$ service docker status
* Docker is running

If it’s not running , run service docker start to start docker engine.

*** Curtains Raising ***

It’s time to run our first container :D

It’s just one line.

Run : docker run hello-world

(don’t kill me after reading this) :D

$ docker run hello-world
Unable to find image ‘hello-world:latest’ locally
latest: Pulling from library/hello-world
0e03bdcc26d7: Pull complete
Digest: sha256:1a523af650137b8accdaed439c17d684df61ee4d74feac151b5b337bd29e7eec
Status: Downloaded newer image for hello-world:latest
Hello from Docker!
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 the Docker Hub.
(amd64)
3. The Docker daemon created a new container from that image which 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/

Now to understand , what happened in background. Please read this carefully.

We just executed , docker run hello-world , what is hello-world?

Hello-world is our image tag, now the docker client connects to docker daemon, and looked for the hello-world image in our local environment

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

but to it’s poor luck, the engine cannot find it locally hence its looks in the registry, which is a place where you will store all your image. In this case, it will pull the image from docker’s default registry.

latest: Pulling from library/hello-world
0e03bdcc26d7: Pull complete

and the output of the image is printed on screen , which is good for learning and people tend to ignore it ( PS. I also did) :D

Hello from Docker!
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 the Docker Hub.
(amd64)
3. The Docker daemon created a new container from that image which 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

To check your container,

execute the following command

$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
1ada3cb24eb7 hello-world “/hello” 4 minutes ago Exited (0) 4 minutes ago modest_lederberg

Name of the container is : modest_lederberg

Please take a minute to appreciate your efforts. You made it. Learnt something new. :) Congratulations

Follow me on linkedin,

https://www.linkedin.com/in/meghalchhabria3/

Cheers :D

--

--