-
Notifications
You must be signed in to change notification settings - Fork 5.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Define host volumes in the volumes
section of the Compose file
#2957
Comments
I believe the only way to do this is to inline the path in the service:
|
Thank you for your responce.
Is there any chance for having having such feature in the next release? |
volumes
section of the Compose file
It is possible, but at this time it's not a high priority, we can keep the issue open to track it, and see if there is other interest in this feature. |
i'm interessing |
i'm interesting |
+1 |
Did you try using
This was with docker-compose |
yes love to have this feature |
+1 |
@patuf @bigfoot90 can you point me to a direct example of this feature? |
@jmarcos-cano I'm not sure I got your request right - do you want to see how it's working or do you want to know why we might need to have bind-mounted volumes in docker-compose? |
@patuf I want to see how to use it, I'm not able to find any documentation |
@jmarcos-cano Please see the comment from @tomfotherby in this very thread, dated 27 March. Replace $PWD with your preferred host directory (absolute path) and it should work. |
For me, on Linux, it works using literally |
Does not work for me.
and:
docker-compose.yml: version: "2"
services:
update:
image: composer
command: ["update", "--no-dev", "--ignore-platform-reqs", "--no-ansi", "--no-interaction", "--no-progress", "--no-scripts", "-a", "-d", "/app"]
volumes: ['code:/app']
volumes:
code:
driver_opts:
type: none
device: $PWD
o: bind Error:
PS: |
has anyone benchmarked the bind mount option? I just tried this on Ubuntu Zesty 17.04 and it seems WAY slower on a read heavy php app (TYPO3 CMS) spread across 2 containers (alpine apache2 and alpine php 7.0) |
@tomfotherby 's solution works but the syntax is way to complicated. It took me a while to find this issue and the workaround. And since it doesn't work on all environments, it's not really usable. Has anyone found a better solution? |
@rakshazi Did you try making your docker-compose file version 3.2+ rather than 2? The documentation says "the long syntax is new in v3.2". Or perhaps you might need two dollar signs? |
No, I missed it, thank you! |
Was able to mount a named, shared volume with the following config:
However, the docs really aren't much of a help at the moment! |
I am trying to define global
When I run
When I run
|
@mhyousefi Are you using From the docs:
edit: I just saw that @katcaola already said this as well: #2957 (comment) |
Thanks to a response by @thaJeztah in this issue, I was able to resolve my issue: "Because you're using the compose-file V1 schema, and that schema does not have support for defining volumes (i.e., no volumes: section); https://docs.docker.com/compose/compose-file/compose-file-v1/#volumes-volume_driver So when parsing your compose-file with the V1 schema, volumes: is seen as the name of a service, and logstash_dir: is seen as an option for that service, which of course is not valid." |
This does currently not work with files. If one specifies a file, an error message is thrown telling that it is not a folder.
|
Thanks @thaJeztah ! Previously I had:
which copied the contents of my app/web/static to /usr/src/app/static each time I docker-compose up'd Now I have
which works locally, but not in Perhaps this is better suited as a stackoverflow question, but I suppose it can be though of here as a request for more documentation about volumes in circumstances like there. |
@thaJeztah That is a very clear description of o:bind . Can you please give me some pointers how can I enable acl on those bind mounted named volume ? I tried to pass |
i'm also "interessing" xD |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
not stale |
This issue has been automatically marked as not stale anymore due to the recent activity. |
How do I mount a volume that doesn't copy into the host, but passes the data through to the FTP share? If I use the bind command when using the volumes in docker-compose I can't get it to work. I'm willing to invest the time to figure this out, but first I would like to know if the bind option would solve my problem. I'm currently trying to mount a mounted FTP share. So I have an FTP shared mounted on my host. It's an external drive offsite with lots of storage space. Then I run docker on my host and I try to write to the FTP share, but it also creates an "overlay" of data on top of my host as well as writing to the FTP share. This is terrible since my host only has 25 Gigs of freespace, while the FTP share has over a TB. I'm running ownCloud and want to write directly to the mount point without the copy of data that is existing in the container. Is there anything I can do? my syntanx is a bit different than the documentation so I'm having an impossible time using the bind command anyways. Here is the syntax: services:
version: '2.1'
volumes:
files:
driver: local
mysql:
driver: local
backup:
driver: local
redis:
driver: local
owncloud:
image: owncloud/server:${OWNCLOUD_VERSION}
restart: always
ports:
- 10.0.8.1:${HTTP_PORT}:8080
depends_on:
- db
- redis
environment:
- OWNCLOUD_DOMAIN=${OWNCLOUD_DOMAIN}
- OWNCLOUD_DB_TYPE=mysql
- OWNCLOUD_DB_NAME=owncloud
- OWNCLOUD_DB_USERNAME=owncloud
- OWNCLOUD_DB_PASSWORD=owncloud
- OWNCLOUD_DB_HOST=db
- OWNCLOUD_ADMIN_USERNAME=${ADMIN_USERNAME}
- OWNCLOUD_ADMIN_PASSWORD=${ADMIN_PASSWORD}
- OWNCLOUD_MYSQL_UTF8MB4=true
- OWNCLOUD_REDIS_ENABLED=true
- OWNCLOUD_REDIS_HOST=redis
healthcheck:
test: ["CMD", "/usr/bin/healthcheck"]
interval: 30s
timeout: 10s
retries: 5
volumes:
# - /mnt/ftp_share/ownCLOUD:/mnt/data
# - type: bind
- files:/mnt/data
# - type: bind
# source: /mnt/ftp_share/ownCLOUD
# target: /mnt/data/files/admin/files/SMBstorage
- /mnt/ftp_share/ownCLOUD:/mnt/data/files/admin/files/SMBstorage
db:
image: webhippie/mariadb:latest
restart: always
environment:
- MARIADB_USERNAME=owncloud
- MARIADB_PASSWORD=owncloud
- MARIADB_DATABASE=owncloud
- MARIADB_MAX_ALLOWED_PACKET=128M
- MARIADB_INNODB_LOG_FILE_SIZE=64M
healthcheck:
test: ["CMD", "/usr/bin/healthcheck"]
interval: 30s
timeout: 10s
retries: 5
volumes:
- mysql:/var/lib/mysql
- backup:/var/lib/backup
redis:
image: webhippie/redis:latest
restart: always
environment:
- REDIS_DATABASES=1
healthcheck:
test: ["CMD", "/usr/bin/healthcheck"]
interval: 30s
timeout: 10s
retries: 5
volumes:
- redis:/var/lib/redis
#end It took me ages to even get docker to write to the FTP share. I had to mount it with all kinds of flags. So I mount the ftp share inside my Ubuntu 18 host. Via a cifs, command, come to think of it, my FTP share might be an SMB share, but anyways, it doesn't matter the method I used to mount to the host, because docker can write to the mount point just fine. But docker creates this overlay of data on top of the host. So every file I upload to the SMB share, goes into my 1TB external drive, but also gets copied into the volume so the host loses freespace. Is there anything that can be done about this wasted space? |
Should be useful for cases when volume already defined at Dockerfile and no possibility to redefine it at docker-compose.yml as directory binding. This didn't solve this case: #2957 (comment) Tried it just now with postgres:12.2-alpine and have no success using described above and methods as with previous versions. Data still saves at volume, not at host directory. I see only way - to rewrite Dockerfile. |
I have been using this http://blog.code4hire.com/2018/06/define-named-volume-with-host-mount-in-the-docker-compose-file/ for a while. No ideea if it covers all the use cases described here. |
I just wanted to point out that I too suffered from some confusion around this issue, which I summarized in #7524 (comment). See also: #6697 |
This adds support for manual bind mounts as named volumes specified as described in docker/compose#2957.
This adds support for manual bind mounts as named volumes specified as described in docker/compose#2957.
Is there a way to run it inside wsl 2 so I have no file path problem from my windows executing jetbrains ide ? |
try prefixing the path with |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
This issue has been automatically closed because it had not recent activity during the stale period. |
This is not stale. AFAIU this OP question was not resolved? I am too interested in possibility of specifying host path in the volumes section of docker compose. |
@ruslaniv So you want to do what @alexlenail provided?
|
@agowa338 Basically yes, although I could not find anything in Docker docs related to this issue, so I'm not sure how "official" so to speak the proposed solution is. |
@ruslaniv If you want you can add it to the documentation. Until now apparently nobody could be bothered to do so. The functionality is a direct result of using the mount option attribute "o" of the none volume. This will than pass these parameters to "mount" and perform the bindmount. |
It seems that there is not the possibility to mount a host directory using the
volumes
section using the versrion 2I would propose an configuration example
My use case:
docker-compose.yml
Override docker-compose.prod.yml
The text was updated successfully, but these errors were encountered: