dockerdocker-composemountfuses3fs

Can I use a docker volume with S3FS?


I would like to have a shared directory between my containers: ftp and s3fs. Todo so, I have created a volume in my docker-compose file called s3.

If I stop s3fs from running in my s3fs container, then I can create files in the ftp container and they will show up in side s3fs under /home/files.

However, when running s3fs the directory /home/files remains empty whilst I create files in the ftp.

This is what my /proc/mounts file looks like:

/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

I belive fuse maybe overriding my docker volume, has anyone encountered this problem before?

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"]

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 && 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"]

Solution

  • You can mount s3 in your docker container in next way

    1.Add to 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.Create entrypoint.sh with next script

    #!/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>
    

    3.In docker-compose.yml add 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