简体   繁体   中英

Persist data from docker container to host machine

I am running docker on windows 10 laptop, I've set up my first container running Elasticsearch using a Dockerfile and it works. Every time I stop the container and start it again the data is gone.

On my windows machine I created a folder in location C:/Docker/esdata and in my elasticsearch.yml I've added path.data: /usr/share/elasticsearch/data is were data is. In the Dockerfile I added:

VOLUME /c/Docker/esdata:/usr/share/elasticsearch/data

but this still doesn't work, can someone tell me what i'm doing wrong.

Your Dockerfile specifies the attributes of the image... the things that are the same no matter where you run the container.

VOLUME /c/Docker/esdata:/usr/share/elasticsearch/data

Is not doing what you think it is doing- you cannot force someone who runs your image later to mount that specific folder. (VOLUME takes a single argument, the path inside the container that is to become seperate from the copy-on-write file system) Instead, you mount the volume at run time with a docker run command...

docker run -v /c/Docker/esdata:/usr/share/elasticsearch/data

This mounts a path on your machine to a path in the running container. However, as pointed out above, /c/Docker is not available to the virtual machine running docker, you will have to do something more like

/c/Users/Docker/esdata:/usr/share/elasticsearch/data

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM