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?
There are two ways where you can create a volume, bind mounts and volumes. Whichever you choose, once you have set up a volume to the folder where the data is stored in the container, if you do a docker-compose down , and then a docker-compose up , your data will not be erased and it will become persistent.
You can use the -v option of docker run to copy volume data between a data volume container and the host. For example, you might want to back up the data so that you can restore it to the same data volume container or to copy it to a different data volume container.
Multiple containers can run with the same volume when they need access to shared data. Docker creates a local volume by default.
Stops containers and removes containers, networks, volumes, and images created by up .
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 Show activity on this post.
Docker named volumes Named volumes can be defined as internal (default) or external. 2.1. Docker internal named volumes Docker compose internal named volumes have the scope of a single Docker-compose file and Docker creates them if they don’t exist.
Get your docker compose stack into state you want to preserve These scripts assume you’re using docker-compose (not docker deploy ), which prepends named volumes with the current directory name. The named values are stored as bzip archives in the current folder with names ending in .tar.bz.
The main advantage of using Docker Compose is that it works in all environments such as production, staging, development, testing, as well as CI workflows. Here at Bobcares, we often use Docker Compose to manage Docker Volumes of our customers using Docker.
Yes you can do it normally, just an example below: Set external to true and set name to the name of the volume you want to mount.
version: "3.5"
services:
transmission:
image: linuxserver/transmission
container_name: transmission
volumes:
- transmission-config:/config
- /path/to/downloads:/downloads
ports:
- 51413:51413
- 51413:51413/udp
networks:
- rede
restart: always
networks:
rede:
external: true
name: rede
volumes:
transmission-config:
external: true
name: transmission-config
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With