Answers: <p><code>docker-compose up</code> will remove containers when:</p>
  
  <ul>
  <li>The service name is the same, but has a change, in which case the old container is replaced with the new state of the service</li>
  <li>You include the <code>--remove-orphans</code> option when running <code>docker-compose</code></li>
  </ul>
  
  <p>Otherwise, if you change the name of the service, and do not specify <code>--remove-orphans</code>, you will see "orphaned" containers still running.</p>
  
Answers: CC BY-SA 4.0
Answers: 2019-05-13T08:09:59.993Z
Answers: The service name is the same for me, because it's the same service, just newer version. So there's no way to prevent this behavior? Maybe remove the name from the container somehow?
Answers: Oren Shpigel
Answers: CC BY-SA 4.0
Answers: 2019-05-13T09:40:03.980Z
Answers: You can change the project name to spin up a second project. That's `docker-compose -p new_project up -d`
Answers: BMitch
Answers: CC BY-SA 4.0
Answers: 2019-05-12T14:52:24.060Z
Answers: 2019-05-12T14:52:24.060Z
Answers: BMitch
Body: <p>I am running a CI/CD pipeline that builds my service and ends with <code>docker-compose up -d</code> which brings up the service with a new docker image tag (<code>my-service:tag1</code>).</p>
  
  <p>But when I look at <code>docker ps -a</code> the previous container (that was running image <code>service:tag0</code>) does not appear anymore, and I cannot access its logs.</p>
  
  <p>Why does docker-compose remove the previous container?</p>
  
  <p>Is there a way to see the logs of the previous containers? </p>
  
Tags: <docker><docker-compose><continuous-deployment><cicd>
Title: How to keep previous containers on docker-compose up?
UserDisplayName: Oren Shpigel
ThreadText: # How to keep previous containers on docker-compose up?
  
  (Asked by: username_0 on 2019-05-12)
  
  I am running a CI/CD pipeline that builds my service and ends with `docker-compose up -d` which brings up the service with a new docker image tag (`my-service:tag1`).
  
  But when I look at `docker ps -a` the previous container (that was running image `service:tag0`) does not appear anymore, and I cannot access its logs.
  
  Why does docker-compose remove the previous container?
  
  Is there a way to see the logs of the previous containers?
  
  **Tags:** docker, docker-compose, continuous-deployment, cicd
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2019-05-12. Score: 3
  
  `docker-compose up` will remove containers when:
  
  * The service name is the same, but has a change, in which case the old container is replaced with the new state of the service
  * You include the `--remove-orphans` option when running `docker-compose`
  
  Otherwise, if you change the name of the service, and do not specify `--remove-orphans`, you will see "orphaned" containers still running.
  
  > **Comments:**
  > **username_0**: The service name is the same for me, because it's the same service, just newer version. So there's no way to prevent this behavior? Maybe remove the name from the container somehow?  
  > **username_1**: You can change the project name to spin up a second project. That's `docker-compose -p new_project up -d`  
  
  ---
  
  