2

I have been trying to setup a graph database using orientdb. So I tried using volumes by the following command

docker run -d -p 2424:2424 -p 2480:2480     -v config:/orientdb/config     -v database:/orientdb/databases     -v backup:/orientdb/backup     -e ORIENTDB_ROOT_PASSWORD=mypasswdhere     orientdb:latest

My prime motive behind using volumes was to store data in database after I kill the container.
But I used this command frequently to start the server.

Now it has hogged my disk space so I guess it creates a new copy each time this command is executed.

Can someone indicate a correct way to use existing volumes to use stored data in docker and to clean up the redundant data recreated by frequent execution of this command?

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • there is cleanup command for containers, images and volumes. dont have those in my memory at the moment, but you can easily sesrch, imo – YOU May 23 '16 at 10:23

2 Answers2

4

You can create named volumes with docker volume create

$ docker volume create --name hello
$ docker run -d -v hello:/world busybox ls /world

That way, only one volume in /var/lib/docker/volumes will be used each time you launch that container.
See also "Mount a shared-storage volume as a data volume".

In the meantime, to remove dangling volumes:

docker volume ls -qf "dangling=true" | xargs docker volume rm
Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • I will like to point out that I never used command like `docker volume create --name hello` to add the new volume but I am directly using `docker run -d -p 2424:2424 -p 2480:2480 -v config:/orientdb/config -v database:/orientdb/databases -v backup:/orientdb/backup -e ORIENTDB_ROOT_PASSWORD=mypasswdhere orientdb:latest ` to run my database each time is that a problem because I see a lot of alphanumeric volume name except 'config' ,'backup' and database (that I gave) when I run `docker volume ls` command. Is that a problem? – Abhimanyu Shekhawat May 23 '16 at 11:57
  • @Abhimanyu in that case, you would mount a local host folder "config" to :/orientdb/config. It is best to create a named volume and mount that volume. – VonC May 23 '16 at 12:04
  • @Abhimanyu I still think that creating a named volume would allow you to reuse it no matter how you create or reuse your container. In other words, you initially chose the right answer ;) – VonC May 24 '16 at 06:56
1

As far as I understand, you aren't re-using the container, instead you start a new one each time. After the first run, you can stop and the restart it with docker stop/start commands.

Roberto Franchini
  • 1,016
  • 7
  • 13