Understanding Docker

Rohit Sai Nallapati
4 min readMay 31, 2021

--

What is Docker?

It is an open platform for developing, shipping, and running applications and it enables us to separate our applications from our infrastructure in order to deliver software quickly. With Docker, we can manage our infrastructure in the same way as we manage applications. In another way, Docker is a bit like a virtual machine. But unlike a virtual machine, it won’t create a whole virtual operating system, this allows applications to use the same Linux kernel as the system that they’re running on and only requires applications to be shipped with things not already running on the host computer. This gives a significant performance boost and reduces the size of the application.

Why do you need docker?

As we can see from the above image the confusion of the developer to connect each other while launching an OS. To Avoid this Docker was introduced following were the uses of Docker.

  • Compatibility/Dependency
  • Long setup time
  • Different Dev/Test/Prod environments

What can Docker do?

  • Containerize Applications
  • Run each service with its own dependencies in separate containers

Docker containers encapsulate everything and application needs to run, allow applications to be shuttled easily between environments.

Docker Container

A container is a runnable instance of an image. We can create, start, stop, move, or delete a container using the Docker API or CLI, Also we can connect a container to one or more networks and attach storage to it and create a new image based on its current state. By default, a container is relatively well separated from other containers and its host machine. Still, we can control an isolated container’s network, storage, or other underlying subsystems are from other containers or from the host machine.

Containers vs Virtual Machines

The virtual machine is simple, it’s a virtual server that runs on a hardware server. A virtual machine depends on the system’s physical hardware to run the exact same environment in which the way you install your applications. Depending on your use case, you can use a system virtual machine or process virtual machines that let you execute computer applications alone in the virtual environment.

Docker Architecture

Docker’s architecture is also client-server-based. However, it’s a little more difficult than a virtual machine because of the features involved. This consists of four main parts:

  1. Docker Client
  2. Docker Objects
  3. Docker Daemon
  4. Docker Registry

Docker Commands

  • docker run — Runs a command in a new container.
  • docker start — Starts one or more stopped containers
  • docker stop — Stops one or more running containers
  • docker build — Builds an image from a Docker file
  • docker pull — Pulls an image or a repository from a registry
  • docker push — Pushes an image or a repository to a registry
  • docker export — Exports a container’s filesystem as a tar archive
  • docker exec — Runs a command in a run-time container

Check out the complete list of commands in the Docker documentation

Creating a new Docker Image

Simple Web Application

Below are the steps required to get this working on a base Linux system.

  • Install all required dependencies
  • Install and Configure Web Server
  • Start Web Server

1. Install all required dependencies

Python and its dependencies

apt-get install -y python python-setuptools python-dev build-essential python-pip python-mysqldb

2. Install and Configure Web Server

Install Python Flask dependency

pip install flask
pip install flask-mysql

import os

from flask import Flask

Code:

app = Flask(__name__)

@app.route(“/”)

def main():

return “Welcome!”

@app.route(‘/Docker is Amazing’)

def hello():

return ‘I am good, how about you?’

if __name__ == “__main__”:

app.run(host=”0.0.0.0", port=8080)

  • Copy the above code in a file called app.py
  • Configure database credentials and parameters

3. Start Web Server

Start webserver

server started
FLASK_APP=app.py flask run --host=0.0.0.0

4. Test

Open a browser and go to the URL

http://<IP>:5000                            => Welcome
http://<IP>:5000/how are you => I am good, how about you?

if you did everything right!! then you will get this output

hurrayyyyyyy!!!! We have done our main task of creating a Docker image.

here is another image of the whalesay!!!

In this way, we can containerize everything we want!!

Like this, we can run other applications on the docker container too.

Thanks for reading!!!!!!!!!!!

--

--

Rohit Sai Nallapati
0 Followers

Cloud Enthusiast || AWS || Web Development