<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Laurap on Medium]]></title>
        <description><![CDATA[Stories by Laurap on Medium]]></description>
        <link>https://medium.com/@laurap_85411?source=rss-a4e5c7fe9e92------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*LBokA55j2PONQZc_CCK7mQ.png</url>
            <title>Stories by Laurap on Medium</title>
            <link>https://medium.com/@laurap_85411?source=rss-a4e5c7fe9e92------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 21:34:24 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@laurap_85411/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Docker compose stop VS down]]></title>
            <link>https://medium.com/@laurap_85411/docker-compose-stop-vs-down-e4e8d6515a85?source=rss-a4e5c7fe9e92------2</link>
            <guid isPermaLink="false">https://medium.com/p/e4e8d6515a85</guid>
            <category><![CDATA[docker-image]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[docker-compose]]></category>
            <dc:creator><![CDATA[Laurap]]></dc:creator>
            <pubDate>Mon, 25 Mar 2024 15:44:09 GMT</pubDate>
            <atom:updated>2024-03-25T15:57:39.916Z</atom:updated>
            <content:encoded><![CDATA[<h3>Introduction</h3><p>First project, a poorly mastered local test flow and I broke the preprod. The main root cause? I didn’t really know the difference between docker-compose stop and docker-compose down.</p><p>A few days ago, I joined an association to help them develop an open-source project. On discovering the project, when I wanted to launch the application for the first time, I took a look at the Makefile. I discovered that a docker-compose down was always executed to stop the application. Immediately, the memories of my mistake mentioned above (and explained in the rest of the article 😉 ) came back to me and the questions flooded in: why not use a docker-compose stop instead? Is one better than the other? And finally, in what context is it preferable to use one rather than the other?</p><h3>Stop, down, what does it do?</h3><h3>Down</h3><p>The docker-compose down command stops and deletes the containers, networks, volumes and images defined in your docker-compose.yml file. This yaml file describes the services, networks, volumes and other configurations required to run an application made up of several <a href="https://www.sipios.com/blog-posts/docker-everything">Docker containers</a>. Btw if you are interested in reading other tech articles like this one, you can learn a lot by reading my company <a href="https://www.sipios.com/blogs/tech-blog">tech blog</a>, especially about <a href="https://www.sipios.com/blog-posts/docker-everything">docker containers</a> ;) .</p><p>To sum up, down reverses the effects of docker-compose up.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IzzwDYFNsfHxYexpgHqqSA.png" /></figure><p>docker-compose up</p><ul><li><strong><em>Docker Image</em></strong><em>: This is the basic model from which containers are created. It contains the code, dependencies and configuration required to run an application.</em></li><li><strong><em>Docker Container</em></strong><em>: These are running instances of a Docker image. Each container has its own file system and can be started, stopped, moved or deleted independently.</em></li><li><strong><em>Docker Volume</em></strong><em>: This is a persistent storage space that can be mounted on a container. It allows data to survive container life cycles. It involves the “sharing” of a local folder between the host and the Docker container. Unlike a simple copy, this is a real-time synchronization, meaning that changes made to this folder are immediately reflected on disk for both container and host.</em></li><li><strong><em>Docker Network:</em></strong><em> A Docker network is a virtual infrastructure that enables communication between Docker containers, whether they are on the same host or on different Docker hosts.</em></li></ul><h3>Stop</h3><p>The docker-compose stop command stops containers associated with services defined in the docker-compose.yml file, without deleting other resources such as networks, volumes, etc.</p><p>The containers are stopped, but retain their state, which means that the data stored in the containers (for example, in Docker volumes) remains intact. It’s important to understand that it’s the associated resources (volume, network config) that retain their state. The container itself, in particular its memory (~RAM), is lost.</p><p>Containers can be restarted later using the docker-compose start command.</p><p>This command is useful when you want to temporarily stop containers without losing associated data or configurations. People often use docker-compose stop by default because it’s faster (to both stop and remount the container), especially if there are large volumes of files.</p><h3>How best to use them ?</h3><h3>When can docker-compose down help me ?</h3><p>Looking around a bit, I found <a href="https://github.com/docker/compose/issues/1487">an example</a> in which it is interesting to use a docker-compose down. On September 15, 2016, <a href="http://twitter.com/wting">@wting</a> posted a message on github: when using docker-compose build, containers are not rebuilt correctly, which leads to problems with a Varnish container due to outdated lock files.</p><p><a href="http://twitter.com/denephin">@denephin</a> replies that the error most likely stems from the fact that the lock file is in a volume and advises him to do a docker-compose down to delete the old containers and their volumes before running an up again to create new ones.</p><p>When Docker Compose rebuilds containers with docker-compose build, it tries to reuse existing containers if possible. So if a container’s configuration hasn’t changed, Docker Compose can simply restart the existing container instead of creating a new one. In this case, even if docker-compose build is run, persistent files in the Varnish container, such as lock files, are not automatically cleaned up. <a href="http://twitter.com/wting">@wting</a> could also have used docker-compose up --force-recreate, to force all containers to be recreated, even if their configuration hasn’t changed.</p><p>By using docker-compose down, we can be sure that our environment is in a clean state, ready to be rebuilt from scratch.</p><h3>When can docker-compose down be harmful?</h3><p>Remember when I told you I’d broken the preprod? Here’s how it happened. A liquibase migration had been done recently and we finally wanted to change the name of the migration file because it contained a special character that blocked windows users (in this case one of our Product Owner).</p><p>I had got into the habit of using docker-compose down in my local test flow. I’d thought the filename change was trivial, but it wasn’t. In other words, it wasn’t enough to change the filename and restart a migration. However, given my test flow, I didn’t realize this during my local test.</p><p>Indeed, docker-compose down deletes images and volumes, and therefore my DB. So when I ran my application locally to test my changes, my DB was re-generated locally, so there was no conflict with the file name. A completely different story when I merged into preprod and broke the environment…</p><h3>Conclusion</h3><p>In conclusion, docker-compose stop is useful when you simply want to stop containers without losing persistent data or associated configurations. This allows you to restart containers at a later date without having to rebuild the entire environment.</p><p>Using docker-compose down can be dangerous, and you need to understand the consequences. It is appropriate when you need to completely clean up your Docker environment. For example, when you want to delete a local database or clean up a project.</p><h3>Sources</h3><p><a href="https://stackoverflow.com/questions/46428420/docker-compose-up-down-stop-start-difference">docker-compose up, down, stop start difference</a></p><p><a href="https://ioflood.com/blog/docker-compose-down-guide-to-stopping-and-removing-docker-containers/">‘Docker Compose Down’ — Guide To Stopping and Removing Docker Containers</a></p><p><a href="https://www.reddit.com/r/devops/comments/ovkhwa/do_you_need_to_do_dockercompose_down_every_time/">Do you need to do docker-compose down every time you change your dockerfile before doing docker-compose up?</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e4e8d6515a85" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>