我可以在只读卷下安装可写的Docker卷吗?

我可以在只读卷下安装可写的Docker卷吗?

问题描述:

我试图将可写的Docker卷挂载为只读卷的子卷,但出现此错误:

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"

我正在处理WordPress映像,我要装载的两个卷是:

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


  • / var / www / html / wp-content:包含我的开发代码。只读,因为我不需要任何意外的更改。

  • / var / www / html / wp-content / uploads:用户上传的文件。必须是可写的。

快速解决方案是将上载移到其他地方,但是我更喜欢Docker解决方案。

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

我的docker-compose.yml的相关位:

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 


回答我自己的问题:挂载点必须存在于只读卷中,即使不会使用也是如此。 Docker试图在挂载之前在RO卷中创建 uploads 目录。

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.

当我在 / dev创建一个空目录时/ workspace / wp-content / uploads ,错误消失,一切都按预期进行。

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