title: docker-compose: difference run, exec and what happens to the layers
body: <p>As far as I understood <code>docker</code> and <code>docker-compose</code> the flow is like that:</p>
  <pre><code>Dockerfile --build--&gt; Docker Image --create--&gt; Docker Container #1
                                     --create--&gt; Docker Container #2
                                     --create--&gt; ...
                                     --create--&gt; Docker Container #n
  </code></pre>
  <p>So the <code>Image</code> is made by the commands in the <code>Dockerfile</code> but is purely some sort of &quot;offline&quot; version. You can bring it &quot;online&quot; then as a Container.</p>
  <p>In my understanding <code>docker-compose up</code> is doing this 2-step process for us by the <code>service</code> definitions inside <code>docker-compose.yml</code>, beside some other stuff like mounting volumes, exposing ports and so on.</p>
  <hr />
  <p><strong>My first question is:</strong></p>
  <p>If I run <code>docker-compose exec some_command</code>, then I am manipulating the docker container - right?</p>
  <p>As far as I have understood the documentation, <code>docker-compose run some_command</code> is doing nearly the same, but, it is creating a new &quot;layer&quot; beforehand, so sth. like this:</p>
  <pre><code>Docker Container #n (layer 0) ----&gt; Docker Container #n (layer 1)
  </code></pre>
  <p>While the <code>some_command</code> is then executed on the layer 1 - right?
  Furthermore it seems like <code>run</code> is passing <code>some_command</code> to the entrypoint, while <code>exec</code> does override the defined entrypoint.</p>
  <p><strong>My second question is:</strong></p>
  <p>What happens to the new layer created by <code>run</code> afterwards? Is there a way to execute the command without creating a new layer? I would like to know that because I added an entrypoint-script like this:</p>
  <pre><code>#!/bin/sh
  
  case &quot;$@&quot; in
      &quot;update&quot;)
          pip3 install -r requirements.txt
          ;;
      &quot;start&quot;)
          python manage.py runserver
          ;;
      *)
          echo &quot;executing $@&quot;
          exec &quot;$@&quot;
          ;;
  esac
  </code></pre>
  <p>I did so in order to be able to run some common tasks like setup, update, ... by running just a short command like <code>docker-compose run backend update</code>. The problem is that the layer that is created by <code>run</code> is not used if I run <code>up</code> afterwards.</p>