Re-using existing volume with docker compose

jonuxas picture jonuxas · Feb 10, 2020 · Viewed 7.9k times · Source

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?

Answer

Ronald Carvalho picture Ronald Carvalho · Aug 7, 2020

Yes you can do it normally, just an example below:

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:
      name: rede
volumes:
  transmission-config:
    external: true
    name: transmission-config