Reuse containers with `docker-compose`

I’ve an app running on multiple Docker containers defined by docker-compose. Everything works fine from my user and the docker-compose ps output looks like:

       Name                Command           State     Ports
------------------------------------------------------------
myuser_app_1    /config/bootstrap.sh   Exit 137
myuser_data_1   sh                     Exit 0
myuser_db_1     /run.sh                Exit 143

Now I’m trying to run docker-compose up with supervisord (see relevant part of supervisord.conf below) and the issue is that the containers are now named myapp_app_1, myapp_data_1 and myapp_db_1, that is they’re created from scratch and all customizations on the former containers is lost.

  • Capture output from attached docker container
  • Spotify docker-maven-plugin unauthorized: authentication required public repo
  • How can I create predictive mappings between network interface names and bridged networks in docker
  • How to transfer large files between dockerized services?
  • Trying to run Docker resulted in exit code 127
  • How to expose a service running inside a docker container, bound to localhost
  • I tried renaming the containers, but it gives an error saying that there’s already a container with that name.

    Q: Is there some way to force docker-compose reuse existing containers instead of creating new ones based in their respective images?

    supervisord.conf

    ...
    [program:myapp]
    command=/usr/local/bin/docker-compose
        -f /usr/local/app/docker-compose.yml up
    redirect_stderr=true
    stdout_logfile=/var/log/myapp_container.log
    stopasgroup=true
    user=myuser
    

  • How to restart php-fpm inside a docker container?
  • Submit docker which contains fat jar to Spark cluster
  • Docker in “host” networking mode does not bind ports to the host
  • Can I run a .Net web application on Dockers for windows?
  • unable to pull any docker images on redhat 7.1
  • When mounting named volumes, under what conditions is data copied from the container?
  • One Solution collect form web for “Reuse containers with `docker-compose`”

    Compose will always reuse containers as long as their config hasn’t changed.

    If you have any state in a container, you need to put that state into a volume. Containers should be ephemeral, you should be able to destroy them and recreate them at any time without losing anything.

    If you need to initialize something I would do it in the Dockerfile, so that it’s preserved in the image.

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.