K2xL
K2xL

Reputation: 10330

Understanding Mounted Directories with Fig and Docker

I am confused about fig and docker containers.

I am trying to get Elastic Search up and running on my vagrant box.

So I have a fig yml that looks like this:

elasticsearch:
  image: dockerfile/elasticsearch
  ports:
    - "9200:9200"
  expose:
    - "9200"
  volumes:
    - /docker_data/elasticsearch:/data

I run it, and elastic search runs fine. I then curl some data in there and I see it.

Concerning the volumes portion of the fig yaml - I've tried to mount the /data folder inside the elasticsearch container onto docker_data, so that way the data will stay persisted.

However, what is very confusing is that when I go into my host vagrant machine and cd into /docker_data/elasticsearch ... It's empty?

When I cd into the /data directory of my elasticsearch container ... it is also empty.

The strange thing is is that the data is persisting - so I am struggling to find out where the data is actually stored in the docker container as according to the docs the data should be stored there.

I run into the same issue when replacing elasticsearch with mysql - When I mount the /var/lib/mysql , it appears empty on both the container and the host.

The strangest part is that everything stays persisted anyway if I remove the volumes part. So now I'm confused how that's happening and why I even need to mount the volume anyway.

I am running docker 1.4.1

Upvotes: 1

Views: 736

Answers (1)

schmunk
schmunk

Reputation: 4708

I had exactly the same problems understanding volumes.

What you try to do is mounting a volume from your container onto your host, which is not possible (AFAIK as of Docker 1.4.1).

You can only mount a volume from your host into your container, which is what you are doing and why it's empty, since Docker creates an empty directory for you and mounts this "over" the existing data in the container.

If the container would write into /data now, it would also appear on your host machine, but be careful about permissions when doing so, especially with Vagrant or boot2docker.

If you remove the volumes, the container persists its /data, because this folder is defined as a volume the Dockerfile of the container. Check the documentation for details about the syntax and persistence of volumes.


Addon: What you could do when you need to get something from the container, is mounting /docker_data/elasticsearch:/data-to-copy and then fig run elasticsearch cp -r /data /data-to-copy. But I doubt this is useful for data, although I do something similar in a project, but for source-code of an application template.

Upvotes: 2

Related Questions