I've got a docker-container that's running a program which outputs something. I want that something to be stored on my local file system, not in a volume. Bind mounts are what I need.
I have a single folder called oniongen and this is where I want the output.
My compose file looks like this:
version: '3'
services:
oniongen:
image: nwtgck/mkp224o
volumes:
- ./oniongen:/gen
command: >
sh -c "mkp224o abcd -d gen"
However, the outputs never reach my local file system.
I've tried
volumes:
oniongen:
driver: local
and this incarnation just in case
volumes:
oniongen:
and also specifying bind under volume type
services:
oniongen:
image: nwtgck/mkp224o
volumes:
- type: bind
source: ./oniongen
target: /gen
volumes:
oniongen:
I've tried other suggestions too and read the docs, but can't seem to get the output stored locally.
If I sh into the container I can see the gen folder and the files in it.
How do I get these files to be stored on my local system?
You're really over-complicating it, just mount a local folder as your volume:
services:
oniongen:
image: nwtgck/mkp224o
volumes:
- ./oniongen:/gen
No need for the volumes top level declaration either.
This will result in everything the container puts in its /gen folder appearing in the host's ./oniongen folder and vice-versa.
Related
I'm running Docker on Windows and I've used docker-compose to start a container which created a folder containing the following folders/files:
docker-compose.yml
data
|___conf
| |__config.yaml
|
|___plugins
|___storage
I want to be able to back up the data that is stored in the container, I can see the data is being generated inside the storage directory. I've looked online and they say to back up volumes I would need to spin another container up and stop my current container etc... Can't I just write a script to back up that storage directory or better yet the entire data directory so that my data doesn't get lost?
My docker-compose.yml looks like this:
version: '3'
services:
verdaccio:
image: verdaccio/verdaccio:4
container_name: verdaccio
environment:
- VERDACCIO_PORT=4873
ports:
- "4873:4873"
volumes:
- "./data/storage:/verdaccio/storage"
- "./data/conf:/verdaccio/conf"
- "./data/plugins:/verdaccio/plugins"
volumes:
verdaccio:
driver: local
I am using owncloud docker image to create my owncloud. The problem is it's storing the data inside the docker image. However, I want one of my driver ( I am using windows) to be used as data files.
volumes:
files:
driver: local
services:
owncloud:
volumes:
- files:/mnt/data
This is what part of the docker-compose files looks like, I tried changing files:/mnt/data to .:/mnt/data. However, I started getting error when I tried to run the docker-compose.
The right way is to use double quotes to expand . as the current directory:
version: '3'
services:
nginx:
image: nginx
volumes:
- ".:/path/inside/container/"
What is the meaning of {} in volume definition?
For example
version: '2'
volumes:
dataelasticsearch: {}
services:
elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:5.4.3
volumes:
- ./dataelasticsearch:/usr/share/elasticsearch/data
It's just an empty mapping. It just means that no extra options were given to the named volume.
From the tests I have done, this is no different from leaving it blank like:
volumes:
dataelasticsearch:
The docker-compose docs do not give any more insights into this.
One more thing: you are defining a named volume at the top but then you are binding a mounted volume in the service:
volumes:
- ./dataelasticsearch:/usr/share/elasticsearch/data
Here ./dataelasticsearch basically creates a folder in your local directory which is mounted as a volume. If you want this feature, you do not need the named volume at all.
What's the right way to mix named volumes with and without local host path in docker compose v3?
This way I'm getting YML error:
volumes:
/mnt/volume-part1:/volume
conf:
vhost:
html:
certs:
Then I'd like to refer to volume inside containers...
For named volumes, you need to declare the volume name under the dedicated volumes section in the compose file. For a mount, you don't declare it in that section:
Consider the following compose file:
version: "3"
services:
db:
image: db
volumes:
- data-volume:/var/lib/db
- /mnt/volume-part1:/volume
volumes:
data-volume:
As you can see the named volume data-volume needes to be declared in the volumes section before being assiged to the container.
Whereas the directory mount is directly mounted onto the container.
UPDATE
If you don't want to replicate the machine path on all the container, you can use a clever trick to specify where exactly the named volume will be created as such:
version: "3"
services:
db:
image: db
volumes:
- data-volume:/var/lib/db
- volume-part1:/volume
volumes:
data-volume:
volume-part1:
driver_opts:
type: none
device: /mnt/volume-part1
o: bind
As you can see above, we have created a named volume volume-part1 and specified where this volume will be backuped on the host machine.
Example below creates dbdata named volume and references it inside db service:
version: '2'
services:
db:
image: mysql
volumes:
- dbdata:/var/lib/mysql
volumes:
dbdata:
driver: local
(from https://stackoverflow.com/a/35675553/4291814)
I can see the path for the volume defaults to:
/var/lib/docker/volumes/<project_name>_dbdata
My question is how to configure the path on host for the dbdata volume?
With the local volume driver comes the ability to use arbitrary mounts; by using a bind mount you can achieve exactly this.
For setting up a named volume that gets mounted into /srv/db-data, your docker-compose.yml would look like this:
version: '2'
services:
db:
image: mysql
volumes:
- dbdata:/var/lib/mysql
volumes:
dbdata:
driver: local
driver_opts:
type: 'none'
o: 'bind'
device: '/srv/db-data'
I have not tested it with the version 2 of the compose file format, but https://docs.docker.com/compose/compose-file/compose-versioning/#version-2 does not indicate, that it should not work.
I've also not tested it on Windows...
The location of named volumes is managed by docker; if you want to specify the location yourself, you can either "bind mount" a host directory, or use a volume plugin that allows you to specify a path.
You can find some details in another answer I posted recently; https://stackoverflow.com/a/36321403/1811501