What is Docker?
Docker is an open platform for developing, shipping, and running applications. Docker allows you to containerize the application. In other words, Docker is capable of making your application platform-independent so that you can deliver the software quickly. Docker follows a “build once, run anywhere” approach, and this is achieved by Docker containers.
Understanding these three essential terms simplifies the comprehension of Docker:
1. Dockerfile
2. Docker Image
3. Docker containers
What is a Dockerfile?
Dockerfile is a simple text document that contains the set of instructions to creating a Docker Image.
Sample Dockerfile format:
FROM <ImageName> (you can find any images on Dockerhub)
WORKDIR app
COPY demo.txt .
The instruction is not case-sensitive. However, convention is for, tools needed to run the application. them to be UPPERCASE to distinguish them from arguments more easily.
What is a Docker Image?
After creating Dockerfile, you can build the Docker image by running the command
docker build -t <Imagename> .
So each instruction in the Dockerfile is executed sequentially to build an image. A Docker image will contain your application code, libraries, and dependencies needed to run the application. Docker images have multiple layers, and they are read-only files, each originating from the previous layer but different from it, promoting reusability and reducing disk usage. A Docker image is a sort of template to create one or multiple containers. Docker images are immutable; that is, they can’t be changed but can be shared, duplicated, or deleted.
What are Docker Containers?
A container is a standard unit of software that packages up code and all its dependencies so the application runs quickly and reliably on any operating system. Containers provide an isolated environment for your application, so the application can run without affecting the system or other applications. Docker containers help to eliminate the “It runs on my computer” problem by providing a consistent environment for running applications across different systems and platforms.
Once Docker image is created, you can have a docker container by firing the following command:
docker run -d <imagename>
To check the list of containers: docker ps -a or docker container ls
Docker Container Vs Virtual Machine
Docker Containers | Virtual Machine (VM) |
Docker containers shares host OS which makes them light weight. | VM has its own guest OS independent of host OS which leads to larger memory and storage consumptions. |
Docker containers are less resource intensive than VM | VM’s are resource intensive as they to load entire OS to start. |
Docker containers are self-contained packages and can run applications in any environment. As they don’t need a guest OS, they can be easily ported across different environments. | VMs are isolated from the OS, so they may not be ported across different platforms without encountering compatibility issues. |
Docker container shares the kernel with the host OS, they are at risk if there’s any vulnerabilities in kernel. | VM’s are completely isolated as each VM has its own OS which offers tight security. |
Thank you, Happy Learning!!