Docker has revolutionised software development by allowing developers to share an isolated environment that allows the whole team (or set of users) to create, test, and deploy apps in a highly consistent and straightforward manner.
Since the technology has been around for a -relatively- long time, I'm sure you've heard phrases like image, container, volumes, or even Dockerfile. Docker images and containers are two of the most essential ideas in this technology, and many newcomers struggle to discern between the two.
The next sections will explain what Docker images and containers are, as well as the fundamental distinctions between them.
A docker image is an immutable file with numerous layers, each of which corresponds to a filesystem and might include dependencies, scripts, or other settings.
Because each phase may be cached, this stacking improves reusability and speeds up picture creation. Unless it has been updated since the previous build, the following build will now load a step from the cache.
The docker build command is now used to construct an image from a Dockerfile – a text file containing instructions that a user may run on the command line to produce the desired image.
Docker images are the basis of containers. An image is an
ordered collection of root filesystem changes and the
corresponding execution parameters for use within a container
runtime. An image typically contains a union of layered
filesystems stacked on top of each other.
- Docker Documentation
Images are saved in a Docker Registry – the default is Docker Hub, but you may also host your own Docker Registry that only your organisation can access.
You can view all the images on the host machine by running
$ docker images
A Docker Container is now an instance of a Docker image that runs in a totally isolated environment (that is, it is separated from any other process running on the computer) and can be executed on any operating system (portability!).
Containers are portable and lightweight run-time environments that allow users to execute programmes in isolation from the underlying host computer.
A operating container may be halted while retaining its settings and any filesystem modifications so that they can be reused when it is resumed.
A container is a runtime instance of a docker image.
A Docker container consists of
- A docker image
- An execution environment
- A standard set of instructions The concept is borrowed from shipping containers, which define a > standard to ship goods globally. Docker defines a standard to ship software.
- Docker Documentation
Some useful commands for docker containers:
# check the running containers $ docker ps # check all the containers running or stopped $ docker ps -a
Docker is a platform that allows developers to create, execute, and ship programmes. Understanding how to utilise Docker efficiently will undoubtedly benefit you throughout your software development path and career.
As a result, it's essential to first grasp the fundamental ideas and components of the technology, which will allow you to utilise Docker more easily. And this trip begins with your ability to discern between a Docker Image and a Docker Container.
In a word, a Docker Image is a construct made up of several layers as stated in Dockerfile, while a Docker Container is a (running) instance of a Docker Image (and probably the reason why you should use Docker!).