Mariadb-docker: Docker for Windows: cannot write on shared volumes

Created on 7 Feb 2018  路  5Comments  路  Source: MariaDB/mariadb-docker

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
question

Most helpful comment

@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)

All 5 comments

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)

```yaml
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:

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

@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)

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.

These seem related to docker-on-windows/mac:
https://github.com/docker-library/mongo/issues/235#issuecomment-358064467
https://github.com/docker-library/postgres/issues/439#issuecomment-386534353

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

eipiminus1 picture eipiminus1  路  9Comments

shaula picture shaula  路  3Comments

andrerom picture andrerom  路  5Comments

Emporea picture Emporea  路  6Comments

amq picture amq  路  4Comments