Docker Container
A Docker container is a runtime environment with all the necessary components—like code, dependencies, and libraries—needed to run the application code without using host machine dependencies. This container runtime runs on the engine on a server, machine, or cloud instance. The engine runs multiple containers depending on the underlying resources available.
To deploy and scale a set of containers to communicate effectively across different machines or virtual machines, you need a container orchestration platform like Kubernetes. This helps whether your machines are on premises or in the cloud. Kubernetes manages multiple machines, known as a cluster, within the context of container operations.
In depth:¶
Docker container is essentially a lightweight, standalone, and executable package that includes everything needed to run a piece of software, and it is built from Docker images.
To understand the relationship between Docker containers and images, it's important to understand the concept of layers:
Docker Image Layers:¶
Docker images are composed of multiple layers. Each layer represents a set of filesystem changes or instructions that were applied during the image's creation. Layers are immutable, meaning they cannot be modified after they are created.
When you build a Docker image using a Dockerfile, each instruction in the Dockerfile adds a new layer to the image. For example, the RUN instruction installs software packages, the COPY instruction copies files into the image, and so on.
Docker Container:¶
A Docker container is a runtime instance of a Docker image. When you run a Docker container, Docker creates a writable container layer on top of the image's read-only layers. This container layer is ephemeral and exists only as long as the container is running.
The container layer allows changes made to the filesystem during the container's execution, such as writing to files or creating new files, to be isolated from the underlying image layers. This enables containers to be lightweight, portable, and disposable.
Relationship:¶
-
Image Layers: Docker images consist of multiple layers representing filesystem changes or instructions. These layers are immutable and are shared among containers based on the same image.
-
Container Layer: When a Docker container is run, a writable container layer is created on top of the image's read-only layers. This layer captures any changes made to the filesystem during the container's execution.
In summary, a Docker container is not a layer of images but rather an instance of a Docker image with a writable container layer on top. The container layer allows containers to be ephemeral and isolated from the underlying image layers, providing a lightweight and portable runtime environment for applications.
