Table of Content-
- What is Docker
- Virtualization Vs Containerization
- Docker Daemon
- Docker Registry
- Docker Client
- Docker Image
- Docker Container
What is Docker ?
Docker is a tool designed to make it easier to create, deploy, and run applications by using containers. Containers allow a developer to package up an application with all of the parts it needs, such as libraries and other dependencies, and ship it all out as one package.
Virtualization Vs Containerization
Before containerization came into the picture, the leading way to isolate, organize applications and their dependencies was to place each and every application in its own virtual machine. These machines run multiple applications on the same physical hardware, and this process is nothing but Virtualization. But virtualization had few drawbacks such as the virtual machines were bulky in size, running multiple virtual machines lead to unstable performance, boot up process would usually take a long time and VM’s would not solve the problems like portability, software updates, or continuous integration and continuous delivery. Containerization is a type of Virtualization which brings virtualization to the operating system level. While Virtualization brings abstraction to the hardware, Containerization brings abstraction to the operating system.
The server that runs on the host machine. It is responsible for building and managing Docker images.
This is where your Docker images are stored , there are two types of registry public and private .
The Docker Client is a command-line interface (CLI) for sending instructions to the Docker Daemon . The Docker client can communicate with more than one daemon.
The Dockerfile is essentially the build instructions to build the image.
Let's create a Dockerfile For a node.js app .
- Create a file with name Dockerfile .
FROM node:15 // node is base image of node with version 15 WORKDIR /app // optional set our workdir in container COPY package.json . RUN npm install // Build time COPY . ./ // Copy the file to /app EXPOSE 3000 // This line is just for documentation purpose CMD [ "node", "server.js"] // Runtime
Docker Image can be compared to a template which is used to create Docker Containers. So, these read-only templates are the building blocks of a Container. You can use docker run to run the image and create a container. Docker Images are stored in the Docker Registry. It can be either a user’s local repository or a public repository like a Docker Hub which allows multiple users to collaborate in building an application.
It is a running instance of a Docker Image as they hold the entire package needed to run the application.
1) Downloads the image from docker hub
docker pull <image_name>
2) Show all the images present
docker image ls
3) To start a image in container , Container is running environment of image . Run basically do pulls and run at the same time
docker run <image_name>
4) List all running containers
5)Start a container in detach mode
docker run -d <image_name>
6) Stop & Start the container
docker stop/start <container_id>
7) To check the logs
docker logs <container_id/name>
8)To get inside the container
docker exec -it <container_id/names> /bin/bash
Container Port Vs Host Port .
Suppose if I have a redis latest image and specific version of redis running at the same time they run on same port as specified 6379 . To run image I can blind container port to host port . We can run multiple containers on host machine . When we give the same host port then there would be Conflict .
docker run -p6000:6379 redis
Above command will bind the host port 6000 to the container port 6379.
docker run -p6001:6379 redis:4.0
Above command will bind the host port 6001 to the container port 6379.
Wanna learn more about docker
1) Docker deep dive by Nigel
2) Docker (Techworldwithnana)
3) Docker ((freecodecamp)
4) Dockerfile best practices
5) Docker security essentials
Connect with me -
Top comments (2)
Awesome post @harkiratsm! Quick tip so more Ops readers see your content, make sure to use relevant tags so your post also shows up in the pages (like on the lefthand nav).
Thank you Brad !