scanservjs

SANE scanner nodejs web ui

Getting started

Installation and setup

  1. Standard install
  2. Docker install
  3. SANE setup install
  4. Troubleshooting

Configuration

  1. Configuration
  2. Integration
  3. Recipes
  4. Using a proxy

Developing

  1. Development
  2. Localisation
  3. Testing
  4. References
  5. QNAP

View the Project on GitHub sbs20/scanservjs

Running scanservjs under docker

If you’re already running Debian, Ubuntu or similar, and haven’t used docker before then it’s probably easier just to install directly. For what it’s worth, that is my preferred installation method since Docker takes an already complicated situation and makes it more complicated.

Getting started

Get the image and run:

# Get the latest
docker pull sbs20/scanservjs:latest

# Remove old container
docker rm --force scanservjs-container 2> /dev/null

# Run
docker run \
  --detach \
  --publish 8080:8080 \
  --volume /var/run/dbus:/var/run/dbus \
  --restart unless-stopped \
  --name scanservjs-container \
  --privileged \
  sbs20/scanservjs:latest

General notes

:warning: By default, configuration and scanned images are stored within the container and will be lost if you recreate it. If you want to map your scanned images then see mapping section below

✅ The docker image supports arm as well as amd64.

Accessing hardware

Docker is great for certain tasks. But it’s less ideal for situations where the container needs to access the host hardware. The simple solution is to run with --privileged but that gives your container full root access to the host which means you’re putting a lot of trust in the container and it’s often still not sufficient for a working system. It’s better not to do this, but it can be painful to avoid. The cleanest solution is to use SANE over Network.

Using SANE over Network

The best overall implementation with Docker if you can manage it is to share the scanner over the network on the host (where the scanner is connected) and then update net.conf in the container; either using a volume map or setting the SANED_NET_HOSTS environment variable on the docker container.

This user uses docker compose instead. See examples below.

Configuring SANE

Sometimes you will need to configure SANE within the container. The best way to achieve this is just volume mapping.

Example to configure airscan.conf:

# Create your airscan config
cat > ./airscan.host.conf << EOF
[devices]
HP = http://192.168.1.150/eSCL, eSCL

[options]
discovery = disable
EOF

# Now map it
docker run -d \
  --publish 8080:8080 \
  --volume ./airscan.host.conf:/etc/sane.d/airscan.conf \
  --restart unless-stopped \
  --name scanservjs-container \
  --privileged \
  sbs20/scanservjs:latest

Example to configure pixma.conf:

# Create your pixma config
echo "bjnp://192.168.1.5" > ./pixma.host.conf

# Now map it
docker run -d \
  --publish 8080:8080 \
  --volume ./pixma.host.conf:/etc/sane.d/pixma.conf \
  --restart unless-stopped \
  --name scanservjs-container \
  --privileged \
  sbs20/scanservjs:latest

Environment variables

There are some shortcuts available to volume mapping above by using environment variables:

Mapping volumes

To access data from outside the docker container, there are two volumes you may wish to map:

Host attached scanner

If your scanner is connected by USB to the host, and there are standard SANE drivers, then you can map the device. The best way to do this is to map the actual USB ports.

In case you scanner is always plugged to your device:

Ephemeral bus address

In case your scanner is not always plugged in, the device path will change every so often, and the previous solution will stop working. Also, some devices will go to sleep after long idle times, effectively getting “unplugged” and “plugged again” over and over.

This can also happen if your container is running inside a VM resultig in an unstable device id.

In this case, you may use udev so that it starts or re-configures your container whenever your scanner is hot-plugged. This is suggested in the official Docker documentation:

Driverless over the network

If your scanner is driverless over the network, then sane-airscan should be able to figure it out - but it uses Avahi / Zeroconf / Bonjour to discover devices on the local network. You will want to share dbus to make it work (--volume /var/run/dbus:/var/run/dbus).

Note that driverless-mode scanning (using airscan over IPP-USB) often results in problems. If anyone has ideas why (perhaps something additional needs sharing from host to guest) then suggestions are welcome. The documentation may be useful.

Proprietary drivers

If you need proprietary drivers for your scanner then the best solution is either to install the drivers on the host and share it over the network or to create your own docker image based on the scanservjs one and add it in that way.

Here is an example on how one particular Brother scanner model and its driver can be installed in the Dockerfile. The driver (brscan4-0.4.10-1.amd64.deb) needs to be placed next to the Dockerfile, then:

COPY brscan4-0.4.10-1.amd64.deb "$APP_DIR/brscan4-0.4.10-1.amd64.deb"
RUN apt install -yq "$APP_DIR/brscan4-0.4.10-1.amd64.deb" \
  && brsaneconfig4 -a name=ADS-2600W model=ADS-2600W nodename=10.0.100.30

Note: The addition of more backends to the docker container is not planned since it would mostly add cruft for most users who don’t need it.

User and group mapping

When mapping volumes, special attention must be paid to users and file systems permissions.

The docker container runs as root by default. Changing the user’s UID (e.g. by using --user 1000 for docker run) to access scans/configuration from outside docker is not advised since it will cause scans to fail.. If running as a different user is important to you then see the scanservjs-user2001 target in ../Dockerfile.

Your alternatives are:

  1. changing the group of the container to a known group on the host e.g. --user 0:1000. This will keep the user correct (0) but change the group (1000).
  2. building a docker image with a custom UID/GID pairing: clone this repository and run
    docker build --build-arg UID=1234 --build-arg GID=5678 --tag scanservjs_custom .
    

    (with UID and GID adjusted to your liking), then run the custom image (e.g. docker run scanservjs_custom).

  3. as a last resort, changing the host volume permissions e.g. chmod 777 local-volume

Examples

docker run --detach --publish 8080:8080 \
  --env SANED_NET_HOSTS="10.0.100.30" \
  --name scanservjs-container sbs20/scanservjs:latest

Mapped USB device with mapped volumes

docker run --detach --publish 8080:8080 \
  --volume $HOME/scan-data:/var/lib/scanservjs/output \
  --volume $HOME/scan-cfg:/etc/scanservjs \
  --device /dev/bus/usb/001/003:/dev/bus/usb/001/003 \
  --name scanservjs-container sbs20/scanservjs:latest

Use airscan and a locally detected scanner

This should support most use cases

docker run --detach --publish 8080:8080 \
  --volume /var/run/dbus:/var/run/dbus \
  --name scanservjs-container sbs20/scanservjs:latest

A bit of everything

Add two net hosts to sane, use airscan to connect to two remote scanners, add two pixma scanners using the bjnp protocol, don’t use scanimage -L, force a list of devices, override the OCR language and run in privileged mode

docker run --detach --publish 8080:8080 \
  --env SANED_NET_HOSTS="10.0.100.30;10.0.100.31" \
  --env AIRSCAN_DEVICES='"Canon MFD" = "http://192.168.0.10/eSCL";"EPSON MFD" = "http://192.168.0.11/eSCL"' \
  --env PIXMA_HOSTS="10.0.100.32;10.0.100.33" \
  --env SCANIMAGE_LIST_IGNORE=true \
  --env DEVICES="net:10.0.100.30:plustek:libusb:001:003;net:10.0.100.31:plustek:libusb:001:003;airscan:e0:Canon TR8500 series;airscan:e1:EPSON Cool Series" \
  --env OCR_LANG="fra" \
  --volume /var/run/dbus:/var/run/dbus \
  --name scanservjs-container --privileged sbs20/scanservjs:latest

Hosting it on a Synology NAS using Docker

It can be convenient to host scanservjs on the same machine where you store your scans — your NAS. Here’s a possible approach for network scanning with a Synology NAS:

  1. Install the Synology Docker package.
  2. In DSM, create a service user “scanservjs” which will run the Docker container. Make sure to give it write permission to the preferred target location for scans. We’ll use /volume1/scans.
  3. SSH with an admin account onto the NAS and use id to determine the UID and GID of the service user just created:
     admin@synology:~$ id scanservjs
     uid=1034(scanservjs) gid=100(users) groups=100(users),65538(scanusers)
    

    Keep the session open, we’ll need it again in a moment.

  4. On your workstation, download and extract the latest scanservjs release.
  5. In the repository root, create a text file named docker-compose.yml with the following content:
     version: "3"
     services:
       scanservjs:
         build:
           context: .
           args:
             # ----- enter UID and GID here -----
             UID: 1034
             GID: 100
           target: scanservjs-user2001
         container_name: scanservjs
         environment:
           # ----- specify network scanners here; see above for more possibilities -----
           - SANED_NET_HOSTS="10.0.100.30"
         volumes:
           # ---- enter your target location for scans before the ':' character -----
           - /volume1/scans:/var/lib/scanservjs/output
           - ./config:/etc/scanservjs
         ports:
           - 8080:8080
         restart: unless-stopped
    
  6. Copy the entire repository including docker-compose.yml onto your NAS (via smb, sftp, …).
  7. In your SSH session from earlier, cd to the repository location and run
     sudo docker-compose up -d
    
  8. After a medium-sized cup of tea, scanservjs should be available at http://<NAS IP Address>:8080
  9. Bonus: Create a reverse proxy rule in the Application Portal so that scanservjs can be reached via http://scan.synology.lan (or similar). Scanning can be slow, so set the proxy timeouts to 300 seconds or more to prevent timeout issues.

Staging builds

These may be less stable, but also have upcoming features.

If you want to install the latest staging branch (this may contain newer code)

docker pull sbs20/scanservjs:staging
docker rm --force scanservjs-container 2> /dev/null
docker run \
  --detach \
  --publish 8080:8080 \
  --volume /var/run/dbus:/var/run/dbus \
  --restart unless-stopped \
  --name scanservjs-container \
  --privileged sbs20/scanservjs:staging