In this article you will see what is right way to create docker image and right way to write docker file. I am also create video for this article. Please like and share my video. It will motivate me to create more article and video. and Don't forget to subscribe my YouTube channel for get updates.
Let me start with some basic of docker image and docker file. Docker image is a package of minimal OS and necessary application which we can create by write in docker file or committing a container. Refer Docker Document for docker image Docker Document for docker image
Now Let's start with docker images remember points.
-
1) We should be able to reuse Docker image.
-
Eg: I have three environment where i need to create container. In this case we should create common image with variable and while creating container we will pass environment as variable value. You can find basic command for create docker image and container in my previous aritcle.
-
2) Docker images should have parent-child combination
-
Eg: I have two java application. According to micro-service architecture we should run only one service in one container so in this case you should create one tomcat image and we should be able to reuse image for both application.
-
3) We should have signal propagation in our image. It will help us to stop service properly while stopping container.
-
4) Keep following point in mind while writing docker file:
- Docker container should be stateless
- Mysql data directory shouldn't be in container it should be in volume.
- Mysql should be configurable.
- Should be able to destroy and re-create container
- Should have signal propagation so mysql service will be stopped while stopping docker container.
- We should have minimun layer in our Docker image and Size should be less so easily we can build and ship our image.
- If you are using RUN for download any software tar file then you should remove duplicate file in same RUN command.
- For ubuntu users : if you are using apt-get for install any software then you should clean local apt repository in same command. .
-
Eg: Lets take a example of mysql docker image.
Here is my video tutorial for this article.
No comments:
Post a Comment