Search code examples
dockerdocker-composevolumes

Re-using existing volume with docker compose


I have setup two standalone docker containers, one runs a webserver another one runs a mysql for it. Right now I was attempting to have it working with docker-compose. All is nice and it runs well, but I was wondering how could I re-use existing volumes from the existing standalone containers that I have previously created (since I want to retain the data from them).

I saw people suggesting to use external: true command for this, but could not get the right syntax so far.

Is external: true the correct way approach for this, or should I approach this differently? Or can I just specify the path to the volume within docker-compose.yml and make it use the old existing volume?


Solution

  • Per the documentation, using the external flag allows you to use volumes created outside the scope of the docker-compose file.

    However, it is advisable to create a fresh volume via the docker-compose file and copy the existing data from the old volumes to the new volumes