If we need to build end to end tech stack ( for example mongodb,node.js,redis etc..) one will face a lot of issues:
- Compatiblity issues with the OS .If one service is not compatible with the OS then we need to change the OS version which is itself a hectic job
- Compatibility issues with the libraries and dependencies of the OS.
- If a new developer joins the team it will be very difficult for him/her to set the environment as each component needs to be configured separately.
- Testing+development becomes hard.
Here Docker helps us in this situation.. we can containerize each application and can run separately.Containers sits on top of OS kernel and docker gives the tools and services to manage the container easily.
When we run Linux container on top of windows machine,basically docker runs Linux container on top of Linux virtual machine on windows host.
Some of the commands and feature of the docker which I have used are as follows:
docker run imagename //downloads the image and run if not downloaded else runs the local image docker pull imagename //only downloads the image docker ps //list all the of running container docker stop containerid //stops the container docker kill containerid // kills the container docker images //displays all the running image /*To remove the container/* docker rm containerid //make sure before removing the container it is stopped /*To remove the images*/ docker rmi imageid //make sure all the container of that image is deleted first /*To get inside of the container */ docker exec containerid cat /etc/host //displays the list of files docker exec containerid -it bash //to go inside of the container and run commands from inside /*Important command for port mapping */ docker run -p 8080:8080 imagename // mapping port of our system to the port of the container.
One of the best ways and the way which I used to run the docker images is to create a YAML file and by using docker-compose command.