Embarking on Docker

Docker, reducing the "it works on my machine" problem.

·

3 min read

Embarking on Docker

Docker is a platform that allows you to develop, deploy, and run applications in containers. Containers are lightweight, standalone executable packages that encapsulate an application and all its dependencies required to run the application.

We will understand the docker in this sequence:

  1. Docker Basics

  2. Docker Commands

  3. Create Dockerfile, Build the image, and run the container

  4. Docker Architecture(Easier to understand after practical implementation)

Docker Basics

Let's understand the core concepts of Docker:

  1. Dockerfile: Dockerfile is a plain text file containing a series of instructions(Example: - list of ingredients to make a dish). Images are created from Dockerfiles

  2. Images: Images have all the necessary files, libraries, and configurations to run an application. (Example: We collected all the ingredients required to make a dish.)

  3. Containers: Containers are running instances of Docker image. They run in isolated environments and ensure applications behave consistently across different systems. (Example: Dish is ready)

Docker Basic Commands:

  1. docker build -t <image-name> <path>: Builds a Docker image from a Dockerfile located at the specified path.

  2. docker run <image>: Creates and starts a new container from an image.

  3. docker ps: Lists all the running containers.

  4. docker images: Lists all the images available on your system.

  5. docker stop <container>: Halts a running container.

  6. docker start <container>: Starts a stopped container.

  7. docker exec -it <container> <command>: Executes a command inside a running container interactively.

  8. docker rm <container>: Removes a stopped container.

  9. docker rmi <image>: Deletes an image from your system.

  10. docker version: Displays the Docker client and server versions installed on your system.

  11. docker info: Provides detailed information about your Docker installation, including the number of containers, images, and networks.

  12. docker pull <image>: Fetches a Docker image from a registry, such as Docker Hub. For example, docker pull ubuntu downloads the latest Ubuntu image.

Create a Dockerfile:

  • Basic Dockerfile that creates a file and prints its contents in a Linux environment:

  • Build Image with commands: sudo docker build . -t myimage

  • Run the container with the command: sudo docker run myimage

Docker Architecture

(image source: k21academy.com)

  1. Docker client: The Docker client uses the command-line interface (CLI) or API to communicate with the docker daemon to execute commands such as building images, and running and managing containers.

  2. Docker Daemon: Docker daemon is a background process that runs on the host operating system, listens from the docker client, and executes actions such as creating, starting, stopping and managing containers.

  3. Docker Host: A Docker host is a physical or virtual machine on which the docker daemon runs which provides the environment to run the containers and the docker host contains the docker daemon, images, containers, networks, and storage.

  4. Docker Registry: Docker Registry is to store and share images. A well-known public registry is known as Docker hub, Enterprises host their private registry for example AWS container registry and Google Cloud container registry etc.

Wrapping up the article, I've got an understanding of how Docker works with its container magic. Docker as a virtual shipping container making software development better and faster. Happy learning!!