Docker: An overview

Docker has become an essential tool as it helps in platform independence for development teams. Every software has some dependencies. For example, if we are creating a website then for development we should have some software installed on our system. These software are the dependencies, which means a website can not be created without these packages and is dependent on these packages or software.

If a website needs to be created using Laravel then I should have PHP and MySql installed on my machine. Again if Laravel 10 is needed then PHP version 8+ is needed.

Now if some other user wants to work on this and do not have php 8 installed then he can not work on the website. So such issues are taken care of by docker.

What is docker?

So docker is something that provides “programming environment consistency”. Programmers can be on any machine with any operating system and still, they will be able to work on any type of software as docker enables this. Docker achieves this by creating isolated environments called containers.

How docker works?

As Docker says “It all starts with a Dockerfile.”. This link gives the docker file reference https://docs.docker.com/reference/dockerfile/. Dockerfile is created by developers and specifies the environment dependencies and setup instructions for a project.

This docker file is used to create a docker image. This docker image is pushed to docker hub, like we push code to Git Hub. A docker image is a static snapshot of the required environment while a container is the running instance.

Other team members can download the docker image from docker hub and create containers on their machine.

Docker image contains all environments within itself. This means all dependencies are packaged in the docker image. As and when we create a container on our machine then this environment releases itself and sets up a suitable environment for the project and we get an isolated environment or container.

This container holds the environment independent of the machine, providing a consistent and reproducible environment for the project. This isolation eliminates issues arising from differences in operating systems or software versions.

Docker and Git

Now the question is where is the code? Docker is used for environment consistency and git is used for code consistency.

We setup the environment in our machine using docker and then we have two ways to work on code using git.

Option 1: we git clone the code in the container and work in the container and commit within the container… and changes will reflect on the git. It is not recommended as changes made in the container are not persistent unless volumes are configured.

Option 2: we mount the git repo on local machine so that code resides on the machine and we run it with in container. We commit changes from our machine as code is on our machine. This option helps in easier integration using local tools like editor.

Conclusion

This gives an overview of how docker works. I find it a very important concept as more and more people are working remotely. Docker helps maintain consistency in remote work environments. It helps in production deployments, CI/CD pipelines, and scaling applications

Leave a Comment

Your email address will not be published. Required fields are marked *

Share via
Copy link
Powered by Social Snap