<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>

CC BY-SA 4.0
2019-05-13T08:09:59.993Z
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?
Oren Shpigel
CC BY-SA 4.0
2019-05-13T09:40:03.980Z
You can change the project name to spin up a second project. That's `docker-compose -p new_project up -d`
BMitch
CC BY-SA 4.0
2019-05-12T14:52:24.060Z
2019-05-12T14:52:24.060Z
BMitch
<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>

<docker><docker-compose><continuous-deployment><cicd>
How to keep previous containers on docker-compose up?
Oren Shpigel
# 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`  

---

