首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在镜像构建阶段使用gcsfuse

在镜像构建阶段使用gcsfuse
EN

Stack Overflow用户
提问于 2019-06-02 23:56:16
回答 1查看 420关注 0票数 0

我试图在docker build ...命令期间使用gcsfuse以便将工作目录挂载到GCP存储中,我已经在服务器故障中提出了这个问题,因为gcsfuse支持被重定向到它,但我找不到一种方法来使其工作,并且由于它是在云运行实例中,我认为在这里询问可能是一个好主意。

这是原始帖子:

我尝试使用gcsfuse来将应用程序源代码存储在GCP存储桶中,下面是我的Dockerfile:

代码语言:javascript
复制
ARG VERSION

FROM golang:1.12.5-alpine3.9 as gcsfuse-builder

ENV GOPATH /go

RUN apk --update add git=2.20.1-r0 fuse=2.9.8-r2 fuse-dev=2.9.8-r2 \
    && go get -u github.com/googlecloudplatform/gcsfuse

FROM php:$VERSION as base

ARG REVISION

ENV APP_DIR=/srv/app \
    APP_ENV=prod \
    APP_FRONT_CONTROLLER=index.php \
    APP_LOCALE=fr \
    APP_USER=test-user \
    APP_USER_GROUP=test \
    APP_PORT=8080 \
    COMPOSER_ALLOW_SUPERUSER=1 \
    NGINX_DIR=/etc/nginx \
    NGINX_VERSION=1.14.2-r1 \
    PHP_FPM_CONF_DIR=/usr/local/etc/php-fpm.d/ \
    SUPERVISORD_CONF_DIR=/etc/supervisor \
    SUPERVISOR_VERSION=3.3.4-r1 \
    BUILD_SCRIPTS_DIR=/build-scripts \
    GOOGLE_APPLICATION_CREDENTIALS=/srv/app/bucket.json

# Supervisord conf to be copied at the end.
COPY docker/prod/php/scripts/*.sh $BUILD_SCRIPTS_DIR/

# Core dependencies installation (installed as a virtual package in order to remove it later)
RUN apk add --no-cache --virtual .build-deps $PHPIZE_DEPS \
    && apk add --no-cache --virtual .fuse-deps curl sshfs fuse \
    && apk add --no-cache --virtual .bash bash=4.4.19-r1 \
    && apk add --no-cache --virtual .core-php-deps icu-dev=62.1-r0 \
    && rm -rf /var/cache/apk/* \
    && docker-php-ext-install \
        intl \
        opcache \
    && docker-php-ext-configure intl \
    && docker-php-ext-enable opcache \
    && apk del .build-deps .phpize-deps-configure

# User creation
RUN apk add --no-cache --repository http://dl-3.alpinelinux.org/alpine/edge/testing/ --allow-untrusted --virtual .user-deps gosu=1.10-r0 \
    && rm -rf /var/cache/apk/* \
    && addgroup $APP_USER_GROUP \
    && adduser -D -h /home/portfolio -s /bin/bash -G $APP_USER_GROUP $APP_USER \
    && chown -R $APP_USER $BUILD_SCRIPTS_DIR \
    && apk del .user-deps

# Nginx & Supervisor installation
RUN apk add --no-cache --virtual .http-deps nginx=$NGINX_VERSION supervisor=$SUPERVISOR_VERSION \
    && rm -rf /var/cache/apk/* \
    && ln -sf /dev/stdout /var/log/nginx/access.log \
    && ln -sf /dev/stderr /var/log/nginx/error.log

# Filesystem (gcsfuse)
COPY --from=gcsfuse-builder /go/bin/gcsfuse /usr/local/bin
COPY bucket.json $APP_DIR/bucket.json

# Filesystem (gcsfuse binding)
RUN apk add --no-cache --virtual .filesystem-deps curl fuse fuse-dev rsync \
    && mkdir -p $APP_DIR $BUILD_SCRIPTS_DIR \
    && chown -R $APP_USER $APP_DIR \
    && chmod -R 755 $APP_DIR \
    && gcsfuse mybucketname $APP_DIR

COPY docker/prod/php/conf/php.ini $PHP_INI_DIR/php.ini
COPY docker/prod/php/conf/fpm.conf $PHP_FPM_CONF_DIR/fpm.conf
COPY docker/prod/nginx/conf/nginx.conf $NGINX_DIR/nginx.conf
COPY docker/prod/supervisord/supervisord.conf $SUPERVISORD_CONF_DIR/supervisord.conf

# Used to check that PHP-FPM works
HEALTHCHECK --interval=5s --timeout=3s \
  CMD curl -f http://localhost/ping || exit 1

# Production build
FROM base as production

COPY docker/prod/nginx/conf/test.conf $NGINX_DIR/conf.d/test.conf

WORKDIR $APP_DIR

COPY . .

# The vendors are installed after the whole project is copied, this way, we can dump the autoload properly.
# The unrequired directories are also removed.
RUN /bin/bash "$BUILD_SCRIPTS_DIR/install_composer.sh" \
    && /bin/bash "$BUILD_SCRIPTS_DIR/composer_dependencies.sh" \
    && rm -rf $BUILD_SCRIPTS_DIR \
        /usr/bin/git* \
        /lib/apk/db/installed \
        /usr/local/bin/composer \
        node_modules/

EXPOSE $APP_PORT 443

CMD ["/usr/bin/supervisord", "-n", "-c", "/etc/supervisor/supervisord.conf"]

镜像可以在没有gcsfuse的情况下构建,但在构建时使用:

gcsfuse mybucketname $APP_DIR

下面是我遇到的错误:

fusermount: fuse device not found, try 'modprobe fuse' first

在构建docker的过程中,有没有办法让它正常工作呢?

感谢您的支持

EN

回答 1

Stack Overflow用户

发布于 2019-06-04 02:07:51

Google Cloud Run目前不支持绑定挂载。

类似地,我不认为很多docker build环境会让你挂载东西。

我认为您在这里尝试使用反模式。Docker构建应该是封闭的和可重现的,在构建期间连接到GCS以下载可以更改/未版本化的文件不是一个好主意。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56416643

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档