Docker Basics for Beginners![0002]

Docker Basics for Beginners![0002]



“Take the first step in faith. You don’t have to see the whole staircase, just take the first step.”
- Martin Luther King Jr.


When you are just getting started with Docker you should know following thing before you actually do something in it,

No alt text provided for this image


  1. Docker Images
  2. Docker Containers
  3. Dockerfile
  4. Docker Volumes
  5. Port Forwarding / Networking
  6. Docker Compose (Advanced Topic)

Out of all 6 points most important for beginners are first three, so I will be talking about first three in this article,

1. What are Docker Images ?

Although Images, containers and Dockerfile are very closely related , in layman terms I would say,

“Docker Images are a template from which the docker containers are being created.”

In Technical words,

“The image is just the “compiled version” of the “source code” which is the Dockerfile.”

That means when you want to use docker for your application or you want run your application using docker or you want to dockerize your application, you need to create an image of your application/code using something called dockerfile. This is the first step of dockerization followed by creating a container to run that image inside docker.

So what Docker Image is all about ?

  1. An image is an inert, immutable file that’s essentially a snapshot of a container. That means you cannot change the content or properties of the docker image once it is created.
  2. They are created with build command ( I will talk about it in Dockerfile section)
  3. An Image will produce a container when started with run.
  4. It is created with lots of layers as per the dockerfile which we provide.
  5. DockerHub has all the official/unofficial images of every tool/technology we use. For example, you need a server for your java application, let’s say you are looking for Apache Tomcat. You will find that image on DockerHub.

2. What are Docker Containers ?

“If we consider Docker Image as a class , then docker container would an instance of that class to use the properties/methods/functions of that class.”

Interesting thing about containers is they are portable that means when you create a container on one machine you can basically export that to some different machine which supports docker environment.

So what Docker Container is all about ?

=> Containers are running instances of images.

That means if you have created your application’s ( Java, JavaScript , Python etc. ) Image inside docker and when you run that image it will create a container and run your actual application as you do it on your machine while development.

=> They run actual application.

Once you create a container from an Image , it basically gives some environment to run your application which is isolated from your local machine’s environment.

=> They hold your application code & all its dependency.

When we build an Image ( which cannot be modified until we create a new custom image ) it has all of your code & things(Official Images of servers or Java or NodeJS ) which are needed to run your application. As I said containers run your actual code , So in order to run your application it might need some dependency or jars or library or packages. When we fire run command inside docker using one of our image it will copy all code & its dependency to docker container.

3. What is Dockerfile ?

Every time when you build an application and you want to run that application using docker, your application you would want some server or dependencies to run in a way it is supposed to run.

Let’s say you have developed one application called Application X , This X application needs a Server Y to run on.

Now you would find Server Y’s official on Docker Hub. We would need to pull that official image and create your own custom application image to run inside docker as a container. This pulling and creation of images is done by Dockerfile.

Generally you would see following approach / steps when you want to Dockerize your application,

  • Create a Dockerfile for your application
  • Pull image from Docker hub or build from a Dockerfile => Gives a Docker image (not editable).
  • Run the image (docker run image_name:tag_name) => Gives a running instance Image i.e. container (editable)

Now let’s see everything in action,

Following is the example of simple Java Program / Java Application which we would dockerize.

To run this application inside docker I need following dependency,

1. Java environment / Java Image inside docker in which we would be able to run java program / java application easily.

  • Simple Java program which will print something as a output.
No alt text provided for this image
  • Dockerfile for my java application
No alt text provided for this image
  • Creating a custom docker image using “docker build” command
No alt text provided for this image

Each step will create a separate layer and at the end of the last step every layer will be combined together to create Docker Image with some random ID.

  • Let’s now confirm if image is created inside docker using “docker images” command.
No alt text provided for this image

As a output it will print all images. We gave our image name as “java-app”. This confirms we have created image successfully.

  • Final step is to run our image as a container using “docker run {image name/tag}”
No alt text provided for this image

When we run our image it will simply create a container and run our application inside it. As our application has only single print statement which we can see the output of the running application in console.

  • Just to ensure container has been created we can simply run “docker ps -a”
No alt text provided for this image

The tag name for image while building a Docker Image was “java-app” . When we check for the containers inside docker we can cross check with image name/tag is correct.

This is how we Dockerize a simple application!


Well, this was all about this article. I hope I have explained and shared some knowledge. Following are the resources which will helpful to understand these concepts in better way,

  1. Official Documentation
  2. Here is another great explanation.

Keep Learning! 😎 Keep Sharing 😊

To view or add a comment, sign in

More articles by Akash Kamble

Others also viewed

Explore content categories