Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
728 views
in Technique[技术] by (71.8m points)

docker - SSHFS mount in Dockerfile fails unless it's from ENTRYPOINT

I'm attempting to SSHFS from the container to a remote server, with the mount created during the Dockerfile build.

The mount command works if executed in the already running container, and will work if I make the command the entrypoint (but then I have to string on the real entrypoint script on the end with a ; which feels too klugy.)

If I put the command in the Dockerfile with a RUN, it fails with a fuse: device not found, try 'modprobe fuse' first error.

Here's the files...

install.sh

#!/bin/bash

USAGE="install.sh <dir_to_parse> <filetype_to_parse>"
if [ $# -lt 2 ]
  then
    echo "$USAGE"
    exit 1
fi

REMOTE_DIR=$1 FILE_EXTENSION=$2 docker-compose -p '' -f docker-compose.yml up -d --build 

docker-compose.yml

version: "3"
services:
  source.test:
    build:
      context: .
      dockerfile: ./Dockerfile
    image: test.source
    container_name: test.source
    environment:
      ELASTIC_HOST: “http://<redacted>:<redacted>”
      REMOTE_SERVER: <redacted>
      REMOTE_USER: <redacted>
      REMOTE_KEY: /etc/ssl/certs/<redacted>
      FEEDER_URL: http://<redacted>/api
      MONGOHOST: mongo
      WALKDIRS: <redacted>
      REMOTE_DIR: ${REMOTE_DIR}
      FILE_EXTENSION: ${FILE_EXTENSION}      
    volumes:
      - /etc/ssl/certs/:/etc/ssl/certs/
    ports:
      - 127.0.0.1:6000:80
    cap_add:
      - SYS_ADMIN
    devices:
      - "/dev/fuse:/dev/fuse"
    security_opt:
      - "apparmor:unconfined"
networks:
  default:
    external:
      name: test

Dockerfile

FROM ubuntu:18.04

RUN apt-get update && apt-get -y install 
    fuse 
    sshfs
        
COPY <redacted> /etc/ssl/certs/<redacted>
COPY fuse.conf /etc/fuse.conf
RUN chown root:root /etc/fuse.conf
RUN chmod 644 /etc/fuse.conf

RUN mkdir /mnt/filestobeparsed

# Fails with fuse: device not found 
RUN sshfs username@<xxx.xxx.xxx.xxx>:/remote/path /mnt/filestobeparsed -o StrictHostKeyChecking=no,IdentityFile=/etc/ssl/certs/<redacted>,auto_cache,reconnect,transform_symlinks,follow_symlinks,allow_other
ENTRYPOINT tail -f /dev/null

# Works but is klugy
#ENTRYPOINT sshfs username@<xxx.xxx.xxx.xxx>:/remote/path /mnt/filestobeparsed -o StrictHostKeyChecking=no,IdentityFile=/etc/ssl/certs/<redacted>,auto_cache,reconnect,transform_symlinks,follow_symlinks,allow_other;  tail -f /dev/null
question from:https://stackoverflow.com/questions/65848870/sshfs-mount-in-dockerfile-fails-unless-its-from-entrypoint

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...