Is s3fs not able to mount inside docker container?

前端 未结 2 1016
时光说笑
时光说笑 2020-12-29 08:32

I want to mount s3fs inside of docker container.

I made docker image with s3fs, and did like this:

host$ docker run -it --rm docker/s3fs bash
[ root@         


        
2条回答
  •  再見小時候
    2020-12-29 09:29

    Adding another solution.

    Dockerfile:

    FROM ubuntu:16.04
    
    # Update and install packages
    RUN DEBIAN_FRONTEND=noninteractive apt-get -y update --fix-missing && \
        apt-get install -y automake autotools-dev g++ git libcurl4-gnutls-dev wget libfuse-dev libssl-dev libxml2-dev make pkg-config
    
    # Clone and run s3fs-fuse
    RUN git clone https://github.com/s3fs-fuse/s3fs-fuse.git /tmp/s3fs-fuse && \
        cd /tmp/s3fs-fuse && ./autogen.sh && ./configure && make && make install && ldconfig && /usr/local/bin/s3fs --version
    
    # Remove packages
    RUN DEBIAN_FRONTEND=noninteractive apt-get purge -y wget automake autotools-dev g++ git make  && \
        apt-get -y autoremove --purge && apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
    
    # Set user and group
    ENV USER='appuser'
    ENV GROUP='appuser'
    ENV UID='1000'
    ENV GID='1000'
    
    RUN groupadd -g $GID $GROUP && \
        useradd -u $UID -g $GROUP -s /bin/sh -m $USER
    
    # Install fuse
    RUN apt-get update   && \
        apt install fuse && \
        chown ${USER}.${GROUP} /usr/local/bin/s3fs
    
    # Config fuse
    RUN chmod a+r /etc/fuse.conf && \
        perl -i -pe 's/#user_allow_other/user_allow_other/g' /etc/fuse.conf
    
    # Copy credentials
    ENV SECRET_FILE_PATH=/home/${USER}/passwd-s3fs
    COPY ./passwd-s3fs $SECRET_FILE_PATH
    RUN chmod 600 $SECRET_FILE_PATH && \
        chown ${USER}.${GROUP} $SECRET_FILE_PATH
    
    # Switch to user
    USER ${UID}:${GID}
    
    
    # Create mnt point
    ENV MNT_POINT_PATH=/home/${USER}/data
    RUN mkdir -p $MNT_POINT_PATH && \
        chmod g+w $MNT_POINT_PATH
    
    # Execute
    ENV S3_BUCKET = ''
    WORKDIR /home/${USER}
    CMD exec sleep 100000 && /usr/local/bin/s3fs $S3_BUCKET $MNT_POINT_PATH -o passwd_file=passwd-s3fs -o allow_other
    

    docker-compose-yaml:

    version: '3.8'
    services:
      s3fs:
        privileged: true
        image: 
        ##Debug
        #stdin_open: true # docker run -i
        #tty: true        # docker run -t
        environment:
          - S3_BUCKET=my-bucket-name
        devices:
          - "/dev/fuse"
        cap_add:
          - SYS_ADMIN
          - DAC_READ_SEARCH
        cap_drop:
          - NET_ADMIN
    

    Build image with docker build -t .
    Run with: docker-compose -d up

提交回复
热议问题