Docker compose volumes windows path

Volume binding using docker compose on Windows

I recently upgraded my Docker Toolbox on Windows 10, and now my volume mounts no longer work. I’ve tried everything. Here is the current mount path:

I receive an invalid bind mount error.

4 Answers 4

  1. Share nfs path using docker settings

2. execute following command

Set path in docker compose file as shown below

File copied to windows

I think you have to set COMPOSE_CONVERT_WINDOWS_PATHS=1 , see here.

I faced with same issue (I’m using Docker Desktop).

My steps were:

1) Place your folder under drive «C»

2) Open «Settings» in Docker Desktop -> «Shared Drives» -> «Reset Credentials» -> select drive «C» -> «Apply»

3) Open terminal and run (as proposed by Docker Desktop):
docker run —rm -v c:/Users:/data alpine ls /data

4) Open your docker-compose.yml and update path in -volumes :

5) restart docker container

It seems you are using an absolute path located inside C:\Users dir, that didn’t work for me too, if you are using Docker-Toolbox see below.

Overview

Forwarding the ./ relative path in volumes section will automatically get resolved by docker-compose to the directory containing docker-compose.yml file (for example, if your project is in %UserProfile%/my-project then ./:/var/www/html gets /c/Users/my-name/my-project:/var/www/html ).

The problem is that currently (using DockerToolbox-19.03.1 ) only the /c/Users directory gets shared with the Virtual-Machine (toolbox puts docker itself in the VM, which means it has no access to your file system, except mounted shared-directories).

Conclusion

So, basically placing your project there ( C:\Users\YOUR_USER_NAME ) should make ./ work. But not even that worked for me, and we ended up with below _prepare.sh script:

Usage:

  • Place a copy of it beside each project’s docker-compose.yml file.
  • Run it each time the system is turned on (simply double-click it or its shortcut).
  • Done! relative paths should now work even if your project is in another drive (far away and outside of C:\Users dir).

Note:

  • With a little edit, it should work without docker-compose being required.
  • Consider running docker system prune to free disk-space (or simply add docker system prune —force to the above script, on a new line right after mount command).

Running a docker-compose “Getting Started” example causes “Invalid volume specification” on Windows

I am absolutely new to Docker. I followed steps described in Docker Compose’s «Getting Started» tutorial:

  1. Install Docker Toolbox
  2. Start Docker Quickstart Terminal
  3. Add project files
  4. Run docker-compose up command
Читайте также:  Обновления для взломанной windows

And I got following error:

  1. Windows 10 Single Language
  2. Docker Toolbox 1.12.5

Why does it happen? Is there some workaround?

1 Answer 1

I found the solution. The problem was I didn’t set the environment variable COMPOSE_CONVERT_WINDOWS_PATHS . It is described in the CLI variables doc.

So, if this problem exists, you should create new Windows environment variable called COMPOSE_CONVERT_WINDOWS_PATHS and set it to 1 . Or you can create .env file in the path docker-compose.yml is placed with following content:

It will solve this problem.

Not the answer you’re looking for? Browse other questions tagged docker docker-compose or ask your own question.

Linked

Hot Network Questions

Subscribe to RSS

To subscribe to this RSS feed, copy and paste this URL into your RSS reader.

site design / logo © 2021 Stack Exchange Inc; user contributions licensed under cc by-sa. rev 2021.4.16.39093

By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.

Locating data volumes in Docker Desktop (Windows)

I’m trying to learn docker at the moment and I’m getting confused about where data volumes actually exist.

I’m using Docker Desktop for Windows. (Windows 10)

In the docs they say that running docker inspect on the object will give you the source:https://docs.docker.com/engine/tutorials/dockervolumes/#locating-a-volume

however I don’t see this, I get the following:

Can anyone help me? I just want to know where my data volume actually exists is it on my host machine? If so how can i get the path to it?

12 Answers 12

Your volume directory is /var/lib/docker/volumes/blog_postgres-data/_data , and /var/lib/docker usually mounted in C:\Users\Public\Documents\Hyper-V\Virtual hard disks . Anyway you can check it out by looking in Docker settings.

You can refer to these docs for info on how to share drives with Docker on Windows.

BTW, Source is the location on the host and Destination is the location inside the container in the following output:

Updated to answer questions in the comment:

My main curiosity here is that sharing images etc is great but how do I share my data?

Actually volume is designed for this purpose (manage data in Docker container). The data in a volume is persisted on the host FS and isolated from the life-cycle of a Docker container/image. You can share your data in a volume by:

Mount Docker volume to host and reuse it

docker run -v /path/on/host:/path/inside/container image

Then all your data will persist in /path/on/host ; you could back it up, copy it to another machine, and re-run your container with the same volume.

Create and mount a data container.

Create a data container: docker create -v /dbdata —name dbstore training/postgres /bin/true

Run other containers based on this container using —volumes-from : docker run -d —volumes-from dbstore —name db1 training/postgres , then all data generated by db1 will persist in the volume of container dbstore .

Читайте также:  Что такое appdata windows 10 можно ли удалить

For more information you could refer to the official Docker volumes docs.

Simply speaking, volumes is just a directory on your host with all your container data, so you could use any method you used before to backup/share your data.

can I push a volume to docker-hub like I do with images?

No. A Docker image is something you can push to a Docker hub (a.k.a. ‘registry’); but data is not. You could backup/persist/share your data with any method you like, but pushing data to a Docker registry to share it does not make any sense.

Yes, as posted above 🙂

I’m on Windows + WSL 2 (Ubuntu 18.04), Docker v19.03. I found my Docker volumes in this location, type in the Windows file explorer :

You will have one directory per volume.

When running linux based containers on a windows host, the actual volumes will be stored within the linux VM and will not be available on the host’s fs, otherwise windows running on windows => C:\ProgramData\Docker\volumes\

Also docker inspect will list the container configuration, under Mounts section see more details about the persistence layer.

Update: Not applicable for Docker running on WSL.

For Windows 10 + WSL 2 (Ubuntu 20.04), Docker version 20.10.2, build 2291f61

Docker artifacts can be found in

Data volumes can be found in

If you have wsl2 enabled, u can find it in file explorer under \\wsl$\docker-desktop\mnt\host\wsl\docker-desktop-data\data\docker

you can find the volume associated with host on below path for Docker Desktop(Windows)

I have found that my setup of Docker with WSL 2 (Ubuntu 20.04) uses this location:

Where UserName is your user name.

Mounting any NTFS based directories did not work for my purpose (MongoDB — as far as I’m aware it is also the case for Redis and CouchDB at least): NTFS permissions did not allow necessary access for such DBs running in containers. The following is a setup with named volumes on HyperV.

The following approach starts an ssh server within a service, setup with docker-compse such that it automatically starts up and uses public key encryption between host and container for authorization. This way, data can be uploaded/downloaded via scp or sftp.

The full docker-compose.yml for a webapp + mongodb is below, together with some documentation on how to use ssh service:

this is unrelated, but for a fully working example, before any docker-compose call the following script needs to be run:

Update: Please note that you can also just use docker cp nowadays, so the sshd container outlined above is probably not necessary anymore, except if you need remote access to the file system running in a container under a Windows host.

Each container has its own filesystem which is independent from the host filesystem. If you run your container with the -v flag you can mount volumes so that the host and container see the same data (as in docker run -v hostFolder:containerFolder).

Читайте также:  Форматирование диска windows без восстановления

The first output you printed describes such a mounted volume (hence mounts) where «/var/lib/docker/volumes/fac362. 80535/_data» (host) is mounted to «/webapp» (container).

I assume you did not use -v hence the folder is not mounted and only accessible in the container filesystem which you can find in «/var/lib/docker/volumes/blog_postgres-data/_data». This data will be deleted if you remove the container (docker -rm) so it might be a good idea to mount the folder.

As to the question where you can access this data from windows. As far as I know, docker for windows uses the bash subsystem in Windows 10. I would try to run bash for windows10 and go to that folder or find out how to access the linux folders from windows 10. Check this page for a FAQ on the linux subsystem in windows 10.

Update: You can also use docker cp to copy files between host and container.

How to set a path on host for a named volume in docker-compose.yml

Example below creates dbdata named volume and references it inside db service:

I can see the path for the volume defaults to:

My question is how to configure the path on host for the dbdata volume?

3 Answers 3

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:

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

There seems to be some confusion as to why this is the best answer. I’m not 100% the confusion, but the question states

how to configure the path on host for the dbdata volume?

And in the below answer, I have shown how to configure the path on host for the dbdata volume to be not the default of /var/lib/docker/volumes/

_dbdata , but /opt/db/vols/dbdata .

As of docker-compose v3.2 you can now do it as follows:

Note: Many, as I figured if you put version: «3» it would use the newest/latest V3, it doesn’t it uses v3.0 , you MUST specify at a minimum 3.2 to use the below configuration method.

Named volumes must be listed under the top-level volumes key, as shown.

Оцените статью