Table of contents
Each time the $ docker run
command is issued, have you ever wondered what happens behind the scene? What does docker do with the container image we are running, how and where does it fetch the information it uses and how does docker know what is required of it to do? We give thanks to technology but there is more to that smart errand. Technologies are known for their exceptional smartness and just like DNS routing, docker internal processing is no different.
The docker Internal Processing
- Firstly, before a container is run, there is an existing image, the image is the application itself which is to be run in a container or containers.
When we execute for instance $ docker run nginx
docker looks through its local cache within the machine to find the image for which the container would run. Ideally, docker already thinks that there is an image ready within its local domain.
The best practice is to have an image ready in your local machine before running it as a container, else docker could pick any image of its choice not minding the size and other security considerations.
If the specified image is not found within the local image cache, docker takes its search from the local cache to the docker registry, a remote server where docker images are stored for private keeps or public accessibility.
From the report registry, docker downloads the specified image and assigns it a default tag - latest. Which means that the image downloaded is in its latest version. Hence, the best practice is to specify the exact version of the docker image if you do not want the latest version.
From the image gotten from the local cache or downloaded freshly from the docker hub, docker will start running a new container. If a new docker run command is issued with the same image, a new container will also start. Hence docker can run multiple versions or a single container image.
Docker assigns a new virtual IP address on a private network inside the docker engine and by default route port 80 (HTTP) on the host machine as well as inside the container even though one can manually assign a specific port aside from the HTTP port 80 the default port is not known to be free.
Also, depending on the type of application being run in the docker container, TCP or UDP is set to maintain speed/reliable communication between the port(server) and the browser(client).
Finally, the docker will start the container with the guide predefined in the dockerfile built into a docker image.
Reasons For Adoption of Docker
Docker makes use of a shared operating system making it a reality to execute multiple numbers of containers in a single operating system and each of these containers will run as a separate instance bearing a different application within itself thereby making applications highly available at a minimal cost.
Docker supports the DevOps CI/CD pipeline through its build, ship and run a model in a lightweight, portable and self-sufficient container.
Docker is easy to deploy in the Cloud since all public clouds have provisions for deployment in docker through their native container registry.
Docker operations are supported in both the command line and different programming languages.
Docker provides an operating system-independent runtime environment for the applications.
With docker, scalability and flexibility are made easy.
Docker is more secure than an ordinary application. Without authorised access, the containers cannot have access to each other's data and multiple security layers can be added to make the containers more secure.
Docker bundles and configures application source code and its dependency into a single file called the docker image making dependency management easier.
Docker has an inbuilt version control system.
Article inspiration: Anshul on Udemy - DevOps Masterclass