Willzyc
Willzyc

Reputation: 122

Docker container not writing to volume

I want to setup ownCloud with Docker and Docker-Compose. To achieve this I have a docker-compose.yml with 3 containers and their volumes.

version: '2'

  services:
    nginx:
      build: ./nginx
      networks:
        - frontend
        - backend
      volumes:
        - owncloud:/var/www/html
    owncloud:
      build: ./owncloud
      networks:
        - backend
      volumes:
        - owncloud:/var/www/html
        - data:/data
    mysql:
      build: ./mariadb
      volumes:
        - mysql:/var/lib/mysql
      networks:
        - backend

  volumes:
    owncloud:
      driver: local
    data:
      driver: local
    mysql:
      driver: local

  networks:
    frontend:
      driver: bridge
    backend:
      driver: bridge

I also tried it without the data volume. ownCloud could not write to /data or without this volume to /var/www/html/data. The log only shows timestamps whenever I accessed ownCloud. Changing from data:/data to a hosted volume /var/ownclouddata:/data results in no difference.

The Dockerfiles have only one line each: FROM:image

I´ve tried adding RUN mkdir /data, but it didn´t fix anything.

Upvotes: 1

Views: 6052

Answers (1)

Vasuki Dileep
Vasuki Dileep

Reputation: 583

You need to mount the volumes in the Dockerfile something like this.

VOLUME /data

Later in your docker-compose file, you can either use a named volume like you did earlier or simply use it like this.

/mnt/test:/data

Here /mnt/test is your host volume path and /data is your docker container path.

Hope it helps!

Upvotes: 6

Related Questions