AfterAcademy Tech
•
31 Jul 2020

Note: If you are unfamiliar with the concept and need of Docker, please refer here.
To recap what’s being previously stated, the primary advantage of Docker is that it allows us to package an application with all of its dependencies into a standardized unit using containers. Unlike virtual machines, containers do not have high overhead and hence enable more efficient usage of the underlying system and resources.
Installing Docker is a pretty quick process and there is no need for many configurations. You can get the link to download Docker based on your Operating System from here.
Once your installation is done, a common way to test for a successful installation is by using the command →
docker versionLet’s run a simple hello world in Docker to get you started.
Yes, a hello-world container exists in Docker for beginners.
Simply run the command →
$ docker run hello-world
You will get the following message explaining you the entire process of how the command was executed →
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.
Docker images and containers are closely related terms and its common to confuse between the two for beginners. Docker images are built by executing commands in the dockerfile and what it primarily does is that it captures the run-time environment parameters so that if it runs again in some other machine, it runs exactly the same as the current machine. On the other hand, a container is an “instance” of an image.
In simple words,
Let a docker image be a blueprint of a building, a container would then be the actual building!
dockerfiledockerfile is used to specify instructions to create a Docker container. It is essentially a list of commands in a text file(dockerfile has no extension).
You open a dockerfile using the touch command.
$ touch dockerfilebase image such as Ubuntu(OS), SQL to allow a primary setting of the environment. This is done as follows:Syntax: FROM <base-image-name>
Example: FROM ubuntu:latest
mkdir command or setting an existing directory as working directory by usingWORKDIR /<app_name>
# And then copy the contents in the container
COPY . /<app_name>
# Exposing port 8080
EXPOSE 8080
# Installing dependencies
RUN apt-get install -y python
# Running Python
CMD ["python", "main.py"]
Note: The difference between RUN and CMD is that the RUN command is executed while building the image and CMD command is executed when we start the container.
You can find the official reference build dockerfile along with the list of commands used here.
Once the dockerfile is created, you can just build the image using the command
$ docker build .
Docker will find the dockerfile in the current directory and build a docker image based on it.
Besides the commands being described above, some other commonly used commands with their use are as follows:-
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
hello-world latest bf756fb1ae65 6 months ago 13.3kB
$ docker ps
CONTAINER ID IMAGE COMMAND NAMES
e90b8831a4b8 nginx "/bin/bash -c 'mkdir'" my_nginx
00c6131c5e30 telegraf:1.5 "/entrypoint.sh" my_telegraf
$ docker run [<image_name> or <image_id>]
Sometimes, a few command-line arguments are passed in this command depending on the requirements of the container.
start and stop command$ docker start <container_id>
$ docker stop <container_id>
$ docker push <image_name>
$ docker pull <image_name>
rm or rmi command$ docker rm <container_id>
$ docker rmi <image_id>
This was a basic walkthrough to get you started with Docker. You can learn more commands as you keep using Docker and keep avoiding dependency hassles with your client 😉.
Please post your feedback in the comments below.
AfterAcademy Tech
Docker is a platform enabling the creation and use of a containerized app which increases application portability in an efficient way. Read the blog to know more.

AfterAcademy Tech
In this tutorial, we will learn to build the RESTful API using Node and Express. The goal is to make you comfortable in building your RESTful API with Node.js and Express. At the end of this blog, you will be able to build your REST APIs using Node.js and Express.

AfterAcademy Tech
Given a stack of integers st, write a program to reverse the stack using recursion. This problem will clear the concept of recursion.

AfterAcademy Tech
Given a stack, you have to sort it in ascending order. You can use another stack if you need auxiliary space. The problem is asked in Google, Microsoft and Amazon and requires knowledge of Stack and recursion to solve it.
