Docker

jiban swainjiban swain
4 min read

Docker is a platform and set of tools that allows you to develop, deploy, and run applications in containers. Containers are lightweight, portable, and self-sufficient environments that can encapsulate an application and all its dependencies, including libraries and runtime. Docker has become widely popular in the world of software development and DevOps because it simplifies the process of packaging, distributing, and running applications across different environments, such as development, testing, and production.

Key components and concepts of Docker include:

  1. Docker Engine: This is the core component of Docker that enables container creation and management. It includes a server, a REST API, and a command-line interface.

  2. Images: Images are templates for containers. They contain the application code, runtime, libraries, and other dependencies needed to run the application. Images are often built from a Dockerfile, which is a set of instructions for creating an image.

  3. Containers: Containers are instances of Docker images. They are isolated and run in their own environments, separate from the host system and other containers. Containers can be started, stopped, moved, and deleted.

  4. Docker Compose: Docker Compose is a tool for defining and running multi-container applications. It allows you to specify the services, networks, and volumes required for your application in a Compose file.

  5. Registry: Docker Hub is a popular public registry where you can find and share Docker images. You can also set up private registries for your organization to store and distribute Docker images internally.

  6. Orchestration: Docker Swarm and Kubernetes are container orchestration tools that help manage and scale containerized applications in a clustered environment. They automate tasks like load balancing, scaling, and rolling updates.

Docker simplifies the process of software development and deployment by providing a consistent environment from development to production. It's widely used in DevOps workflows and has become a fundamental tool for containerization and microservices architecture.

Basice Docker Commands:-

1-Pull an Image from Docker Hub:-

docker pull IMAGE_NAME[:TAG]

This command downloads a Docker image from Docker Hub to your local machine

2-List Downloaded Images:-

docker images

Use this command to see a list of Docker images that are currently stored on your system.

3-Run a Container:

docker run [OPTIONS] IMAGE_NAME[:TAG]

Start a new container from an image. You can specify options like -d for running in detached mode, -p for port mapping, and more.

4-List Running Containers:

docker ps

View a list of running containers. To see all containers, including stopped ones, use docker ps -a.

5-Stop a Container:

docker stop container name or container ID

Stop a running container. You can use either the container ID or name.

6-Remove a Container

docker rm container name or containner ID

Delete a stopped container. Like with stopping, you can use either the container ID or name.

7-Inspect a Container:

docker inspect CONTAINER_ID or CONTAINER_NAME

Retrieve detailed information about a specific container, including configuration and network settings.

8-View Container Logs:

docker logs container_name or container_ID

Display the logs generated by a running container.

9-Execute a Command Inside a Running Container:

docker exec [OPTIONS] CONTAINER_ID or CONTAINER_NAME COMMAND [ARG...]

Run a command inside a running container. Use -it for an interactive terminal session.

10-Create a Docker Image from a Dockerfile:

docker build [OPTIONS] PATH_TO_DOCKERFILE

Build a Docker image from a Dockerfile located in the specified path.

11-Push an Image to Docker Hub:

docker push IMAGE_NAME[:TAG]

Upload your custom Docker image to Docker Hub or another registry.

12- Find docker images in Docker Hub:

docker search "images_name"

Docker Hub

13-Download from docker Hub to Local Machine:-

docker pull "image_name"

Download from a local machine.

14- Give the Container name and run:

docker run -it --name "give the container name" /bin/bash

15- Check the service start or stop: service docker status

16- Start the docker service:

service docker start

or systemctl start docker

17- Stop the Docker service:

service docker stop or systemctl stop docker

18- To start the Docker Container

docker start "image_name"

19- To go inside the container:

docker attach "image_name"

20- To stop the Docker Container:

docker stop "image-name"

21- Without stopping a container comes out side:

ctrl+p + ctrl+q

22- chack OS version and which OS:

cat/etc/os-release

23- If access to a new container :

docker run -it "image_name" /bin/bash

Hypervisor

Docker is not a hypervisor. It is a containerization technology that allows you to package an application and its dependencies into a single image. This image can then be run on any machine that has Docker installed, regardless of the underlying operating system.

Hypervisor Vs Docker: Tabular Comparison

3
Subscribe to my newsletter

Read articles from jiban swain directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

jiban swain
jiban swain

๐Ÿ‘‹ Hello! I'm Jiban Kumer about DevOps and have over 1.5+ years of experience in the field. I'm proficient in a variety of cutting-edge technologies and always motivated to expand my knowledge and skills. Let's connect and grow together! SKILLS: ๐Ÿ”น Languages & Runtimes: Python, Shell Scripting, HCL, YAML ๐Ÿ”น Cloud Technologies: AWS, GCP ๐Ÿ”น Infrastructure Tools: Docker, Terraform, AWS CloudFormation ๐Ÿ”น Other Tools: Linux, Git and GitHub Actions, Jenkins, Jira, GitLab (beginner), Docker, AWS DevOps