Paulo Victor
Paulo Victor

Reputation: 4122

How can I use a created volume in my container using docker compose?

In docker 1.9 I can create volumes and I can use it on my container as the exemple:

$ docker volume create --name testing-volume
$ docker run -it -v testing-volume:/var/lib/mysql busybox sh -c 'ls -alh/var/lib/'

It will show the mysql folder on the output as expected.

But how can I use a volume using docker-compose?

I saw that ther is a volume_driver directive but it is not working, my last try was like this

docker-compose.yml:

mysql:
   image: percona
   ports:
       "3306:3306"
   environment:
       MYSQL_ROOT_PASSWORD=123456
   volume_driver: testing-volume
   volumes:
       "/var/lib/mysql"

Thanks

Upvotes: 3

Views: 913

Answers (1)

wsilva
wsilva

Reputation: 199

Try this:

mysql:
    image: percona
    ports:
        - "3306:3306"
    environment:
        - MYSQL_ROOT_PASSWORD=123456
    volume_driver: local
    volumes:
        - "testing-volume:/var/lib/mysql"

If you are using any custom driver you can change on volume_driver directive.

Upvotes: 5

Related Questions