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?

1 Answer 1

  • 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 two Dockerfiles and see what they are doing; it should be pretty self explanatory. Then you can either craft a single new Dockerfile mixing and merging lines from the sources, or keep one of the original dependencies as your FROM, and just copy lines from the other original to a new Dockerfile.
  • You would use command in a docker-compose.yml in the same cases when you would give a command on the docker run line, 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 that CMD into the Dockerfile and remove it from the docker-compose.yml. If you find, instead, that you are using different commands all the time, then keep them in docker-compose.yml.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.