我可以将docker卷与S3FS一起使用吗?

我可以将docker卷与S3FS一起使用吗?,docker,docker-compose,mount,fuse,s3fs,Docker,Docker Compose,Mount,Fuse,S3fs,我希望在我的容器之间有一个共享目录:ftp和s3fs。为此,我在docker compose文件中创建了一个名为s3的卷 如果我停止在我的s3fs容器中运行s3fs,那么我可以在ftp容器中创建文件,它们将显示在/home/files下的s3fs侧边 但是,当运行s3fs时,目录/home/files保持为空,而我在ftp中创建文件 这就是我的/proc/mounts文件的外观: /dev/sda2 /home/files ext4 rw,relatime,data=ordered 0 0 s3

我希望在我的容器之间有一个共享目录:
ftp
s3fs
。为此,我在docker compose文件中创建了一个名为
s3
的卷

如果我停止在我的
s3fs
容器中运行
s3fs
,那么我可以在
ftp
容器中创建文件,它们将显示在
/home/files
下的
s3fs
侧边

但是,当运行
s3fs
时,目录
/home/files
保持为空,而我在
ftp
中创建文件

这就是我的/proc/mounts文件的外观:

/dev/sda2 /home/files ext4 rw,relatime,data=ordered 0 0
s3fs /home/files fuse.s3fs rw,nosuid,nodev,relatime,user_id=0,group_id=0,allow_other 0 0
我相信fuse可能会覆盖我的docker卷,以前有人遇到过这个问题吗

docker-compose.yml

version: "3"
services:
  ftp:
    image: app/proftpd:latest
    volumes:
      - s3:/home/files
    ports:
      - 2222:2222

  s3fs:
    image: app/s3fs:latest
    command: start
    env_file:
      - s3fs/aws.env
    volumes:
      - s3:/home/files
    cap_add:
      - SYS_ADMIN
    devices:
      - "/dev/fuse"
    environment:
      ENVIRONMENT: "dev"

volumes:
  s3:
s3fs-Dockerfile

FROM ubuntu:16.04

RUN apt-get update -qq
RUN apt-get install -y \
            software-properties-common
RUN apt-get update -qq
RUN apt-get install -y \
            automake \
            autotools-dev \
            fuse \
            g++ \
            git \
            libcurl4-openssl-dev \
            libfuse-dev \
            libssl-dev \
            libxml2-dev \
            make \
            pkg-config \
            curl

RUN curl -L https://github.com/s3fs-fuse/s3fs-fuse/archive/v1.84.tar.gz | tar zxv -C /usr/src
RUN cd /usr/src/s3fs-fuse-1.84 && ./autogen.sh && ./configure --prefix=/usr --with-openssl && make && make install

COPY entrypoint.sh /opt/s3fs/bin/entrypoint.sh

RUN mkdir -p /home/files

WORKDIR /opt/s3fs/bin

ENTRYPOINT ["/bin/sh", "./entrypoint.sh"]
FROM ubuntu:16.04

RUN apt-get update && apt-get install -y \
    openssh-server \
    proftpd-basic \
    proftpd-mod-mysql

COPY proftpd.conf /etc/proftpd/proftpd.conf
COPY sftp.conf /etc/proftpd/conf.d/sftp.conf
COPY setup.sh /etc/proftpd/setup.sh

RUN chmod 500 /etc/proftpd/setup.sh && /etc/proftpd/setup.sh

EXPOSE 2222

ENTRYPOINT ["/bin/sh", "/etc/proftpd/entrypoint.sh"]
s3fs-entrypoint.sh

#!/usr/bin/env bash

case $1 in

start)
    echo "Starting S3Fs: "
    s3fs mybucket /home/files -o allow_other,nonempty -d -d
;;

esac
ftp-Dockerfile

FROM ubuntu:16.04

RUN apt-get update -qq
RUN apt-get install -y \
            software-properties-common
RUN apt-get update -qq
RUN apt-get install -y \
            automake \
            autotools-dev \
            fuse \
            g++ \
            git \
            libcurl4-openssl-dev \
            libfuse-dev \
            libssl-dev \
            libxml2-dev \
            make \
            pkg-config \
            curl

RUN curl -L https://github.com/s3fs-fuse/s3fs-fuse/archive/v1.84.tar.gz | tar zxv -C /usr/src
RUN cd /usr/src/s3fs-fuse-1.84 && ./autogen.sh && ./configure --prefix=/usr --with-openssl && make && make install

COPY entrypoint.sh /opt/s3fs/bin/entrypoint.sh

RUN mkdir -p /home/files

WORKDIR /opt/s3fs/bin

ENTRYPOINT ["/bin/sh", "./entrypoint.sh"]
FROM ubuntu:16.04

RUN apt-get update && apt-get install -y \
    openssh-server \
    proftpd-basic \
    proftpd-mod-mysql

COPY proftpd.conf /etc/proftpd/proftpd.conf
COPY sftp.conf /etc/proftpd/conf.d/sftp.conf
COPY setup.sh /etc/proftpd/setup.sh

RUN chmod 500 /etc/proftpd/setup.sh && /etc/proftpd/setup.sh

EXPOSE 2222

ENTRYPOINT ["/bin/sh", "/etc/proftpd/entrypoint.sh"]

您可以用下一种方法将s3装载到docker容器中

1.添加到
Dockerfile

RUN apt-get install -y fuse s3fs
RUN mkdir /root/.aws
RUN touch /root/.aws/.passwd-s3fs && chmod 600 /root/.aws/.passwd-s3fs
COPY entrypoint.sh ./
RUN chmod 700 entrypoint.sh
ENTRYPOINT entrypoint.sh
2.使用下一个脚本创建entrypoint.sh

#!/bin/sh
echo "$AWS_CREDS" > /root/.aws/.passwd-s3fs
echo "$BUCKET_NAME /srv/files fuse.s3fs _netdev,allow_other,passwd_file=/root/.aws/.passwd-s3fs 0 0" > /etc/fstab
mount -a
<your old CMD or ENTRYPOINT>
#/垃圾箱/垃圾箱
echo“$AWS\u CREDS”>/root/.AWS/.passwd-s3fs
echo“$BUCKET\u NAME/srv/files fuse.s3fs\u netdev,allow\u other,passwd\u file=/root/.aws/.passwd-s3fs 0”>/etc/fstab
a山
3.在docker-compose.yml中添加next

<your-container-name>:
   image: ...
   build: ...
   environment:
      - AWS_ID="AKI..."
      - AWS_KEY="omIE..."
      - AWS_CREDS=AKI...:2uMZ...
      - BUCKET_NAME=<YOUR backed name>
   devices:
      - "/dev/fuse"
   cap_add:
      - SYS_ADMIN
   security_opt:
      - seccomp:unconfined
:
图片:。。。
建造:。。。
环境:
-AWS_ID=“AKI…”
-AWS_KEY=“omIE…”
-AWS_CREDS=AKI…:2uMZ。。。
-桶名=
设备:
-“/dev/fuse”
第(二)章增补:
-系统管理员
安全选项:
-无侧限

您解决过这个问题吗?我面临着完全相同的问题。不,我最终放弃了使用一个卷,结果只是合并了我的两个docker图像。然后,s3fs能够拾取文件。我不确定为什么使用卷不起作用,我想fuse可能会覆盖它。谢谢@Freid001,我想我最终也会这么做。