<ul>
<li>Yes, one would usually have minimal docker images, i.e., one responsibility per image/container, with appropriate networking between them.</li>
<li>Yes, images are linear, there is only ever one unbroken line of <code>FROM</code>s. To merge two images, get the two <code>Dockerfile</code>s and see what they are doing; it should be pretty self explanatory. Then you can either craft a single new <code>Dockerfile</code> mixing and merging lines from the sources, or keep one of the original dependencies as your <code>FROM</code>, and just copy lines from the other original to a new <code>Dockerfile</code>.</li>
<li>You would use <code>command</code> in a <code>docker-compose.yml</code> in the same cases when you would give a command on the <code>docker run</code> 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 <code>CMD</code> into the <code>Dockerfile</code> and remove it from the <code>docker-compose.yml</code>. If you find, instead, that you are using different commands all the time, then keep them in <code>docker-compose.yml</code>.</li>
</ul>

CC BY-SA 4.0
2018-08-03T18:23:42.837Z
2018-08-03T18:23:42.837Z
AnoE
<p>I am VERY new to Docker and I looking for a confirmation of my views and my usage of Docker in my use-cases.</p>

<p>I'll try it with examples:</p>

<ul>
<li><p>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?</p></li>
<li><p>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?</p></li>
<li><p>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?</p></li>
</ul>

<docker><docker-compose><dockerfile>
Docker: strategy-advise for a rookie
chris01
# Docker: strategy-advise for a rookie

(Asked by: username_0 on 2018-08-03)

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?

**Tags:** docker, docker-compose, dockerfile


---

## 1 answers

### Answer by username_1 on 2018-08-03. Score: 4 | Accepted answer

* 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 `FROM`s. To merge two images, get the two `Dockerfile`s 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`.


---

