I have the following docker-compose file :
version: "3.3"
services:
elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:6.1.1
volumes:
- esdata:/usr/share/elasticsearch/data
environment:
- bootstrap.memory_lock=true
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
- discovery.type=single-node
ports:
- "9300:9300"
- "9200:9200"
volumes:
esdata:
(I removed other services for clarity) I can see the volume in /var/lib/docker/volumes/project_name_esdata but I would like to be able to create the volume in the directory where the docker-compose.yml is but I didn't find a way to do so.
Inspired from How to set a path on host for a named volume in docker-compose.yml, I tried
version: "3.3"
services:
elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:6.1.1
volumes:
- esdata:/usr/share/elasticsearch/data
environment:
- bootstrap.memory_lock=true
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
- discovery.type=single-node
ports:
- "9300:9300"
- "9200:9200"
volumes:
esdata:
driver: local
driver_opts:
type: 'none'
o: 'bind'
device: './'
But that raise the following exception :
Caused by: java.nio.file.AccessDeniedException: /usr/share/elasticsearch/data/nodes
Please, let me know if I should post the full stack trace or any other relevant informations.
You bind local directories and volumes to a container by providing the Docker run -v parameter. You need to give the absolute local path or a volume name and map it to a directory within the container -v <source>:<target> .
First stop the docker service. Then the volumes can be moved from the default location at /var/lib/docker to the new location. Next the configuration of the docker daemon is edited to point to the new location of the volumes. The next step may not be necessary, but it is a good habit to do it anyway.
Though both methods are similar, there is a slight difference. Docker manages Volumes and is usually not affected by other processes running on the same host. In contrast, Bind Mounts are just a directory on the host file system and may be modified by other processes other than docker.
Use the following command to bind-mount the target/ directory into your container at /app/ . Run the command from within the source directory. The $(pwd) sub-command expands to the current working directory on Linux or macOS hosts. If you're on Windows, see also Path conversions on Windows.
If you use ./ the volume will be mounted in the same folder (I have had permissions issues before by doing this just so you know)
version: "3.3"
services:
elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:6.1.1
volumes:
- ./esdata:/usr/share/elasticsearch/data
environment:
- bootstrap.memory_lock=true
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
- discovery.type=single-node
ports:
- "9300:9300"
- "9200:9200"
volumes:
esdata:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With