title: Docker Compose: Change COMPOSE_PROJECT_NAME without rebuilding the application
body: <p><strong>Summary</strong>: </p>
  
  <p>I have an application X, I want to deploy multiple instances of the same application (port numbers will be handled by an .env) in the same OS without starting a <code>build</code> for each instance.</p>
  
  <p><strong>What I tried</strong>:</p>
  
  <p>So I managed to dynamically (by the user changing .env file), change the <code>container_name</code> of a container. But then we cannot run 5 instances at the same time (even if the ports are different, docker just stops the first re-creates the container for second)</p>
  
  <p>Next I came across <code>COMPOSE_PROJECT_NAME</code> that seems to work BUT starts a new build.</p>
  
  <hr>
  
  <p><strong>COMPOSE_PROJECT_NAME=hello-01</strong></p>
  
  <pre><code>docker-compose up
  Creating network "hello-01_default" with the default driver
  Building test
  Step 1/2 : FROM ubuntu:latest
   ---&gt; 113a43faa138
  Step 2/2 : RUN echo Hello
   ---&gt; Using cache
   ---&gt; ba846acc19e5
  Successfully built ba846acc19e5
  Successfully tagged hello-01_test:latest
  WARNING: Image for service test was built because it did not already exist. To rebuild this image you must use `docker-compose build` or `docker-compose up --build`.
  Creating hello-01_test ... done
  Attaching to hello-01_test
  hello-01_test exited with code 0
  </code></pre>
  
  <hr>
  
  <p><strong>COMPOSE_PROJECT_NAME=hello-2</strong></p>
  
  <pre><code>docker-compose up
  Creating network "hello-02_default" with the default driver
  Building test
  Step 1/2 : FROM ubuntu:latest
   ---&gt; 113a43faa138
  Step 2/2 : RUN echo Hello
   ---&gt; Using cache
   ---&gt; ba846acc19e5
  Successfully built ba846acc19e5
  Successfully tagged hello-02_test:latest
  WARNING: Image for service test was built because it did not already exist. To rebuild this image you must use `docker-compose build` or `docker-compose up --build`.
  Creating hello-02_test ... done
  Attaching to hello-02_test
  hello-02_test exited with code 0
  </code></pre>
  
  <hr>
  
  <p><strong>Source files</strong></p>
  
  <p><strong>docker-compose.yml</strong></p>
  
  <pre><code>version: '3'
  services:
    test:
      container_name: "${COMPOSE_PROJECT_NAME}_test"
      build: .
  </code></pre>
  
  <p><strong>.env</strong></p>
  
  <pre><code>COMPOSE_PROJECT_NAME=hello-02
  </code></pre>
  
  <p><strong>Dockerfile</strong></p>
  
  <pre><code>FROM ubuntu:latest
  RUN echo Hello
  </code></pre>
  
  <hr>
  
  <pre><code>Ubuntu 18.04.1 LTS 
  Docker version 18.06.0-ce, build 0ffa825
  docker-compose version 1.21.2, build a133471
  </code></pre>