Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I have a writable Docker volume mounted under a read-only volume?

I'm trying to mount a writable Docker volume as a child of a read-only volume, but I get this error:

ERROR: for wordpress  rpc error: code = 2 desc = "oci runtime error: 
could not synchronise with container process: mkdir /mnt/sda1/var/lib
/docker/aufs/mnt/.../var/www/html/wp-content/uploads: read-only file 
system"

I'm working with a WordPress image, and the two volumes I want to mount are:

  • /var/www/html/wp-content: Contains my development code. Read-only, since I don't want any unexpected changes.
  • /var/www/html/wp-content/uploads: Files that are uploaded by users. Must be writable.

The quick solution is to move uploads somewhere else, but I'd prefer a Docker solution.

Relevant bits of my docker-compose.yml:

volumes:
  uploads:
    driver: local

services:
  wordpress:
    volumes:
      - /dev/workspace/wp-content/:/var/www/html/wp-content/
      - uploads:/var/www/html/wp-content/uploads 
like image 1000
James Beninger Avatar asked Jun 17 '16 14:06

James Beninger


2 Answers

Answering my own question: The mount point must exist in the Read-Only volume, even if it won't be used. Docker was trying to create the uploads directory in the RO volume before mounting it.

When I created an empty directory at /dev/workspace/wp-content/uploads, the error disappeared and everything worked as expected.

like image 101
James Beninger Avatar answered Nov 06 '22 16:11

James Beninger


Yes, in general, you can! Here is an example with the read-only parent path

-v $DIR/htdocs:/var/www/html:ro

and another mount

-v $DIR/logs:/var/www/html/app/cache:rw

See more https://stackoverflow.com/a/37730878/4986182

like image 38
vitr Avatar answered Nov 06 '22 16:11

vitr