且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用gcsfuse挂载Google存储时Docker构建失败

更新时间:2022-11-30 14:38:38

默认情况下,Docker不允许与其他存储(例如GCP)一起挂载。您可以做的是在运行具有特权选项的容器时,可以将其装入存储。

Docker won't allowed to mount with other storages(like GCP) by default. What you can do is when running the container with privileged option you can mount with the storage.

将此命令放入脚本文件(gcp.sh)并构建docker映像。

Put this command in script file(gcp.sh) and build the docker image.

RUN gcsfuse --key-file /creds.json \
  --debug_gcs --debug_http --debug_fuse --debug_invariants \
  --dir-mode "777" -o allow_other spm-bucket /mnt/uploads

gcp.sh:

gcsfuse --key-file /creds.json --debug_gcs --debug_http --debug_fuse --debug_invariants --dir-mode "777" -o allow_other spm-bucket /mnt/uploads

和Dockerfile:

and the Dockerfile:

FROM wordpress
MAINTAINER Gareth Williams <gareth@itinerateconsulting.com>

# Move login creds locally
ADD ./creds.json /creds.json

# install sudo, wget and gcsfuse
ENV GCSFUSE_REPO=gcsfuse-jessie
RUN   apt-get update && \
      apt-get -y install sudo && \
      apt-get install -y curl ca-certificates && \
      echo "deb http://packages.cloud.google.com/apt $GCSFUSE_REPO main" > /etc/apt/sources.list.d/gcsfuse.list && \
      curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add - && \
      apt-get update && \
      apt-get install -y gcsfuse wget && \
      apt-get remove -y curl --purge && \
      apt-get autoremove -y && \
      rm -rf /var/lib/apt/lists/*

# Config fuse
RUN chmod a+r /etc/fuse.conf
RUN perl -i -pe 's/#user_allow_other/user_allow_other/g' /etc/fuse.conf

# Setup sql proxy
RUN sudo mkdir /cloudsql
RUN sudo chmod 777 /cloudsql
ADD https://dl.google.com/cloudsql/cloud_sql_proxy.linux.amd64 cloud_sql_proxy.linux.amd64
RUN mv cloud_sql_proxy.linux.amd64 cloud_sql_proxy && chmod +x ./cloud_sql_proxy
RUN ./cloud_sql_proxy -dir=/cloudsql -fuse -credential_file=/creds.json &
# mysql -u icroot -S /cloudsql/[INSTANCE_CONNECTION_NAME]

# Perform Cloud Storage FUSE mounting for uploads folder
RUN mkdir /mnt/uploads
RUN chmod a+w /mnt/uploads
#RUN chown www-data:www-data -R /mnt && groupadd fuse && gpasswd -a www-data fuse && chmod g+rw /dev/fuse
USER www-data
COPY gcp.sh /home
RUN chmod +x /home/gcp.sh
CMD cd /home && ./gcp.sh

最后,在生成映像后,使用--privileged选项$ b运行容器$ b docker run --privileged

and finally after build the image run the container with --privileged option docker run --privileged