hello-world docker

hello-world docker | Run your first docker container | complete tutorial [2022]

Docker is an excellent technology used by almost all companies around the globe. This tutorial will explain how to pull your first container using Docker. We will be pulling a hello-world docker image from dockerhub. To follow along, I assume Docker is installed and running in your system.

Docker hello world example

Hello-world is the basic image, and the Docker community manages it. Hello, the world image will not create any container; it will just display the output, which shows your docker installation is OK.

Let’s proceed further and pull hello-world image from dockerhub

Docker pull hello-world

Type the docker pull command to pull the hello-world image from the dockerhub

docker pull hello-world
Using default tag: latest
latest: Pulling from library/hello-world
Digest: sha256:9f6ad537c5132bcce57f7a0a20e317228d382c3cd61edae14650eec68b2b345c
Status: Image is up to date for hello-world:latest
docker.io/library/hello-world:latest

If you wish to know more information about what docker pull does, please follow this link

Run the below command to verify if the images pull successfully

docker images
REPOSITORY                     TAG              IMAGE ID       CREATED         SIZE
hello-world                    latest           d1165f221234   3 months ago    13.3kB

docker images command will list the images that are present in your local system

Docker run hello-world

Docker run command starts the docker container from the docker image. Let’s run the hello-world image and verify the output:

docker run hello-world

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/

excellent; if you are getting above output, your hello-world containers are running as expected.

Docker hello-world github

You can visit the Docker hello-world github page to learn more about how this hello-world dockerfile has been written.

The hello-world docker image supports various architecture like amd64,arm32v7,arm32v5 arm64v8, windows-amd64, etc. The hello-world github page has a dockerfile for all the supported architecture.

Docker hello-world windows

Docker is a containerization platform that will perform the same irrespective of where you are installing the image. So to spin up a hello-world docker for windows, we have to follow the same steps we have followed for any other os version.

You can follow this link to install Docker on windows. Once the Docker is successfully installed, you can type the below command to pull the hello-world docker image from the github

docker run hello-world 

You would get the below output if your docker installation were proper.

docker run hello-world                       
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
2db29710123e: Pull complete 
Digest: sha256:cc15c5b292d8525effc0f89cb299f1804f3a725c8d05e158653a563f15e4f685
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/

Docker Hello-world Nginx

In the above session, we have seen how to pull the basic Hello-world docker image from the dockerhub, which is basically used to verify if your docker installation is working as expected.

Now it’s time to move further and pull the Nginx image from the dockerhub. Nginx image is another basic hello-world image that developer uses extensively.

Type the below command to pull the nginx image

docker pull nginx
Using default tag: latest
latest: Pulling from library/nginx
a2abf6c4d29d: Pull complete 
f3409a9a9e73: Pull complete 
9919a6cbae9c: Pull complete 
fc1ce43285d7: Pull complete 
1f01ab499216: Pull complete 
13cfaf79ff6d: Pull complete 
Digest: sha256:366e9f1ddebdb844044c2fafd13b75271a9f620819370f8971220c2b330a9254
Status: Downloaded newer image for nginx:latest
docker.io/library/nginx:latest

Now type the below command to run the nginx image

docker run --name my_nginx -d -p 8081:80 nginx:latest
0b1cd7ba9cd2b5933f749b62d6d5e633f20266a1a5876843f87d8eec1009217c

Goto localhost:8081 to access the nginx UI.

Docker Hello-world Nginx

A more detailed explanation about the nginx image can be found here

Hello world python docker image

So far, we have understood how to build the docker image, which is readily available in the dockerhub.In this session, we will understand how to build a python docker image from scratch.

To create a custom docker image. create a folder name python-hello-world

mkdir python-hello-world

Now create a dockerfile and paste the below content

FROM python:3.7
ADD helloworld.py /
CMD [ "python", "./helloworld.py"]

Dockerfile Explanation:

  1. we have used python:3.7 as a base image
  2. In the second step, we copied the helloworld.py file to / directory.
  3. finally, in the last step, we are running the helloworld.py file

You can check my other blogs to fully understand how to write a dockerfile and the essential things that need to be taken care of while writing one.

What Docker pull does

Undestand Docker layer

Docker base image to use

Now, Create another file, helloworld.py, and paste the below content

print("Hello from Naive-skill")

verify if the python-hello-world folder contains the below files

dockerfile
helloworld.py

Build the docker image by typing the below command

docker build --tag python-hello-world .        
Sending build context to Docker daemon  3.072kB
Step 1/3 : FROM python:3.7
3.7: Pulling from library/python
0e29546d541c: Pull complete 
9b829c73b52b: Pull complete 
cb5b7ae36172: Pull complete 
6494e4811622: Pull complete 
6f9f74896dfa: Pull complete 
fcb6d5f7c986: Pull complete 
7a72d131c196: Pull complete 
c4221d178521: Pull complete 
71d5c5b5a91f: Pull complete 
Digest: sha256:d9abbc0737ff8d23a546859c85903f1b8235a1495a405d5a47cbc55747f27b20
Status: Downloaded newer image for python:3.7
 ---> ad37de9b03ef
Step 2/3 : ADD helloworld.py /
 ---> ae8f839bb059
Step 3/3 : CMD [ "python", "./helloworld.py"]
 ---> Running in 305cdb634f91
Removing intermediate container 305cdb634f91
 ---> 9d426cc74961
Successfully built 9d426cc74961
Successfully tagged python-hello-world:latest

Use 'docker scan' to run Snyk tests against images to find vulnerabilities and learn how to fix them

Now run the docker image by typing the below command

docker run python-hello-world                                    
Hello from Naive-skill

Conclusion

In this blog, we have understood the hello-world docker file and explored nginx and python hello-world images. I hope you liked this basic docker hello-world tutorial. Feel free to ask your valuable questions in the comments section below.

More to Explore

Docker httpd image

Dockerfile tutorial for begineer

Docker logs

Leave a Comment

Your email address will not be published.

Scroll to Top