Skip to content

Docker for Windows: cannot write on shared volumes #152

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

Closed
rahonalab opened this issue Feb 7, 2018 · 5 comments
Closed

Docker for Windows: cannot write on shared volumes #152

rahonalab opened this issue Feb 7, 2018 · 5 comments
Labels
question Usability question, not directly related to an error with the image

Comments

@rahonalab
Copy link

rahonalab commented Feb 7, 2018

as already mentioned here #95 , mariadb container on windows cannot write its database files on a shared volume. Here is a snippet of my docker-compose.yaml

sql:
    image: mariadb
    env_file: ./secrets.env
    domainname: ${DOMAINNAME}
    hostname: ${FIRSTNAME}-sql
    volumes:
      - ./${FIRSTNAME}-container/lib/mysql:/var/lib/mysql
  web:
   image: rahonabe/icinga2-web
   env_file: ./secrets.env
   links:
     - sql
     - core
   domainname: ${DOMAINNAME}
   hostname: ${FIRSTNAME}-web
   build: 
    context: ./web
   ports:
     - 80:80
   volumes:
     - ./${FIRSTNAME}-container/etc/icingaweb2:/etc/icingaweb2
     - ./${FIRSTNAME}-container/webroot_icingaweb2:/usr/share/icingaweb2
     - ./${FIRSTNAME}-container/webroot_nagvis:/usr/local/nagvis
     - ./${FIRSTNAME}-container/lib/php5/sessions:/var/lib/php5/sessions
     - ./${FIRSTNAME}-container/log/apache2:/var/log/apache2
     - ./${FIRSTNAME}-container/certs:/etc/apache2/ssl:ro
     - ./${FIRSTNAME}-container/perfdata:/var/lib/pnp4nagios/perfdata
     - ./${FIRSTNAME}-container/etc/pnp4nagios:/etc/pnp4nagios
   volumes_from:
     - core
     - sql
@yosifkit
Copy link
Contributor

yosifkit commented Feb 8, 2018

The only solution on Docker for Windows is to use a Docker controlled volume, rather than mapping it to your host. And it will still work to share volumes to other containers. (see also, the named volumes conversation here)

version: '3.4'

services:
  sql:
    image: mariadb
    env_file: ./secrets.env
    domainname: ${DOMAINNAME}
    hostname: ${FIRSTNAME}-sql
    volumes:
      - sql-data:/var/lib/mysql

volumes:
  sql-data:

@rahonalab
Copy link
Author

Thank you, I am still confused about Docker volumes and I didn’t get your point. Now it’s clearer, but will data be maintained if the container is deleted?

@yosifkit
Copy link
Contributor

yosifkit commented Feb 8, 2018

@rahonalab, yes the named volume has a life-cycle independent of the container. If you do docker-compose stop and docker-compose rm, then the volume will stick around as sql-data. docker volume ls will let you see ones that are still around (which may be quite a few unused ones) You can get rid of all volumes not currently used by a container with docker volume prune (only while your sql container is running, otherwise your volume will be removed)

@rahonalab
Copy link
Author

rahonalab commented Feb 9, 2018

thank you @yosifkit
I used to develop and run my docker containers in unix environments (mac os and linux) and I am pretty new to docker in windows environments. If I understand it right, docker controlled volumes are more agnostic/universal with respect to the hosting system; mapped volumes worked just fine for me in unix environments, since I can change file attributes without logging into the container, but I see that on windows things are a little bit different.

@wglambert wglambert added the question Usability question, not directly related to an error with the image label Apr 25, 2018
@wglambert
Copy link

wglambert commented May 4, 2018

These seem related to docker-on-windows/mac:
docker-library/mongo#235 (comment)
docker-library/postgres#439 (comment)

Because they use virtualbox there is an issue with sharing folders between the host and container.
See https://www.virtualbox.org/ticket/819

Since the issue seems resolved I'm going to close.
If you believe this to be in error then let me know and I'll re-open it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Usability question, not directly related to an error with the image
Development

No branches or pull requests

3 participants