how to create persistent containers with docker-compose

1k views Asked by At

i wanted to create multiple instances of a service. i have created a compose file, when i run

docker-compose up --scale steam=5 -d 

and then exit , then next time i rerun the command

docker-compose up --scale steam=1 -d 

or a number less than 5 ,the previous created containers get removed.And this is not my only problem. I wanted to make sure upon exit the containers are not removed and the data in them is not lost. The service i want to scale is steam, and i wanted to save the login information from each container so that the next time i start the containers i don't have to re-login in each of them.

More info : Docker Version: 17.09.0-ce API version: 1.32 Go version: go1.8.3 Git commit: afdb6d4 Built: Tue Sep 26 22:42:18 2017 OS/Arch: linux/amd64

docker-compose version 1.15.0, build e12f3b9 docker-py version: 2.4.2C Python version: 2.7.13 OpenSSL version: OpenSSL 1.0.1t 3 May 2016

1

There are 1 answers

1
Simon Schürg On

You could mount a directory from the filesystem of your host in all of your steam containers to store your persistent data. This is the way to have persistent data in docker!

Then it doesn't matter if you do a docker-compose up or docker-compose down. The data is persistet on the host filesystem and next time you do a docker-compose up, the data is available in the container.

If each of your steam containers need a seperate directory for the data, you could use the right directory by defining environment variables for the containers.