1

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
RightmireM
  • 2,381
  • 2
  • 24
  • 42
  • A Docker image is just a filesystem image and some metadata explaining how to run a container; it doesn't include running processes, mounts, or anything else. You can't persist a mounted filesystem like this (and in general you can't mount filesystems inside Docker at all without giving the container unusual extra permissions). – David Maze Jan 22 '21 at 16:37
  • @David Maze Thanks for the comment. A persistent SSHFS mount seems to work OK long-term when mounted from a docker container inside a linux VM on my laptop (to the same remote.) It's only failing when I run the container on an Openstack Linux server. I think you may have already seen the related question `https://stackoverflow.com/questions/64049240/docker-containers-sshfs-mount-freezes-but-only-when-mounted-by-python` The suggestion there was to do the SSHFS mountfrom within the Dockerfile, and not the from within python. But it's having the same issues. – RightmireM Jan 22 '21 at 17:10

0 Answers0