【问题标题】:Unable to mount bucket with gcsfuse on Cloud Run无法在 Cloud Run 上使用 gcsfuse 挂载存储桶
【发布时间】:2022-01-21 04:57:52
【问题描述】:

借助 Google Cloud Run 的第二代运行时,现在可以使用 gcsfuse 挂载 Google 存储桶。

https://cloud.google.com/run/docs/tutorials/network-filesystems-fuse

python3 示例运行良好。不幸的是,我的 Dockerfile 不断出现此错误:

bin/fusermount: failed to open /dev/fuse: Permission denied
mountWithArgs: mountWithConn: Mount: mount: running /bin/fusermount: exit status 1

Dockerfile

# https://github.com/chiaen/docker-gcsfuse
FROM golang:1.17.5-alpine as gcsfuse
RUN apk add --no-cache git
ENV GOPATH /go
RUN go get -u github.com/googlecloudplatform/gcsfuse

FROM composer:2 as vendor
COPY composer.json composer.json
COPY composer.lock composer.lock
RUN composer install --ignore-platform-reqs --no-interaction --prefer-dist

FROM craftcms/nginx:7.4

ENV MNT_DIR /mnt/gcs

USER root
RUN apk add --no-cache mysql-client postgresql-client ca-certificates fuse nano sudo tini bash

RUN mkdir -p $MNT_DIR
RUN chown www-data:www-data $MNT_DIR
USER www-data

COPY --chown=www-data:www-data --from=vendor /app/vendor/ /app/vendor/
COPY --chown=www-data:www-data . .
COPY --from=gcsfuse /go/bin/gcsfuse /usr/local/bin
COPY supervisor.conf /etc/supervisor/conf.d/supervisor.conf

由于文件很少,我把所有文件都放到了一个 github repo 中。 https://github.com/internetztube/cloud-run-persistent-storage-issue

【问题讨论】:

  • 我按照文档中的教程进行操作,它对我有用:cloud.google.com/run/docs/tutorials/…
  • 文档中的示例也适用于我。问题是我在容器中需要 PHP 和 NGINX。我强烈地将自己定位在这个例子上,因此它应该以同样的方式工作,但事实并非如此。 @guillaumeblaquiere
  • 1) 注意这一行 COPY --chown=www-data:www-data 。 . 您尚未在容器中指定 WORKDIR。您可能正在更改容器中的文件权限,具体取决于源目录中的文件。这可能无法解决您的问题,但应该得到纠正。
  • 2) 您正在从主管运行 gcsfuse.sh 脚本。但是,您已将 USER 更改为 www-data。您在 /dev/fuse 上遇到权限错误。作为测试,暂时将 USER 从 www-data 更改为 root 以查看这是否是实际问题。
  • @JohnHanley 我从 Dockerfile 中删除了 USER www-data。另外还在 gcsfuse.sh 中打印了whoami。用户是root。仍然不起作用。我认为这不是权限问题,但底层安装命令有问题。

标签: docker google-cloud-storage google-cloud-run gcsfuse


【解决方案1】:

更新:

我通过以下更改解决了它mounting GCS bucket in Cloud Run 和对象的read/write

  • Dockerfile:
# https://github.com/chiaen/docker-gcsfuse
FROM golang:1.17.5-alpine as gcsfuse
RUN apk add --no-cache git
ENV GOPATH /go
RUN go get -u github.com/googlecloudplatform/gcsfuse

FROM composer:2 as vendor
COPY composer.json composer.json
COPY composer.lock composer.lock
RUN composer install --ignore-platform-reqs --no-interaction --prefer-dist

FROM craftcms/nginx:7.4

ENV MNT_DIR /mnt/gcs

USER root
RUN apk add --no-cache mysql-client postgresql-client ca-certificates fuse nano sudo tini bash
RUN mkdir -p $MNT_DIR
RUN chown www-data:www-data $MNT_DIR

COPY --chown=www-data:www-data --from=vendor /app/vendor/ /app/vendor/
COPY --chown=www-data:www-data . .
COPY --from=gcsfuse /go/bin/gcsfuse /usr/local/bin
COPY supervisor.conf /etc/supervisor/conf.d/supervisor.conf
  • gcsfuse.sh 中添加了-file-mode=777 -dir-mode=777gcsfuse 命令以在GCS 存储桶的挂载目录中启用读/写:
gcsfuse -o rw,allow_other -file-mode=777 -dir-mode=777 --foreground --debug_http --debug_gcs --debug_fuse --implicit-dirs $DISK_BUCKET $MNT_DIR
  • 硬编码路径(/mnt/gcs/demo.txt而不是../storage/demo.txt)以在文件web/index.php中进行测试。

截图输出:

【讨论】:

  • 我认为这不是权限错误,因为/dev/fuse 不存在。在此处获取此错误:sudo: a terminal is required to read the password; either use the -S option to read from standard input or configure an askpass helper sudo: a password is required - 2021-12-21 10:44:23,121 INFO gave up: gcsfuse entered FATAL state, too many start retries too quickly - 2021-12-21 10:44:23,122 INFO reaped unknown pid 19 (exit status 0)
  • 此外,文件更改也不会出现在存储桶管理界面中。
  • @Fred 我已修复,请查看更新后的答案
  • 我也更新了 Github repo!感谢您的努力!
猜你喜欢
  • 2018-05-08
  • 2016-04-17
  • 1970-01-01
  • 2019-09-05
  • 2019-11-21
  • 2020-09-10
  • 1970-01-01
  • 2017-10-19
  • 2017-10-23
相关资源
最近更新 更多