principledockerMinor
Docker: strategy-advise for a rookie
Viewed 0 times
advisedockerforstrategyrookie
Problem
I am VERY new to Docker and I looking for a confirmation of my views and my usage of Docker in my use-cases.
I'll try it with examples:
-
I have a T3 application. Every tier is a basic requirement (lets say persistence with postgres, application with java, presentation with php). Because I find for any tier an image on docker-hub I use them and compose them to have 3 running containers which exchange their data via network. Correct?
-
I have an application that is in java and needs to work on the files of centos (e.g. read logs). There is not interaction - only stdout or files. Docker-images for centos are available, for java too. There is no easy way to create a Dockerfile with a double FROM. So I build my own image from centos and do ADD/COPY/RUN to get a java JDK into it. Correct?
-
I can do in docker-compose.yml also actions that I can have in dockerfile too (e.g. workdir and command). Is it better to keep it in dockerfile and see docker-compose only for assembling multiple containers OR should I put as many things into docker-compose as I can?
I'll try it with examples:
-
I have a T3 application. Every tier is a basic requirement (lets say persistence with postgres, application with java, presentation with php). Because I find for any tier an image on docker-hub I use them and compose them to have 3 running containers which exchange their data via network. Correct?
-
I have an application that is in java and needs to work on the files of centos (e.g. read logs). There is not interaction - only stdout or files. Docker-images for centos are available, for java too. There is no easy way to create a Dockerfile with a double FROM. So I build my own image from centos and do ADD/COPY/RUN to get a java JDK into it. Correct?
-
I can do in docker-compose.yml also actions that I can have in dockerfile too (e.g. workdir and command). Is it better to keep it in dockerfile and see docker-compose only for assembling multiple containers OR should I put as many things into docker-compose as I can?
Solution
- Yes, one would usually have minimal docker images, i.e., one responsibility per image/container, with appropriate networking between them.
- Yes, images are linear, there is only ever one unbroken line of
FROMs. To merge two images, get the twoDockerfiles and see what they are doing; it should be pretty self explanatory. Then you can either craft a single newDockerfilemixing and merging lines from the sources, or keep one of the original dependencies as yourFROM, and just copy lines from the other original to a newDockerfile.
- You would use
commandin adocker-compose.ymlin the same cases when you would give a command on thedocker runline, in case you were running the container manually. That is, if you have an image which conveniently supports different commands, and were it would just be a waste to have a different image per command. So... if you find that you run your container with the same command in 99% of all cases, then put thatCMDinto theDockerfileand remove it from thedocker-compose.yml. If you find, instead, that you are using different commands all the time, then keep them indocker-compose.yml.
Context
StackExchange DevOps Q#4681, answer score: 4
Revisions (0)
No revisions yet.