cups icon indicating copy to clipboard operation
cups copied to clipboard

CUPS does not recognise symlinks to devices in Docker

Open alex-mashin opened this issue 1 year ago • 1 comments

CUPS will not recognise a printer device (Samsung CLP 365W ) symlinked by an UDEV rule at the host and attached to a docker container based on debian:stable-slim. A directly referenced device, however, will be immediately found and suggested by system-config-printer connected to the host.

Dockerfile and the relevant fragment of docker-compose.yml are below.

FROM debian:stable-slim
MAINTAINER Alexander Mashin <[email protected]>
LABEL version=0.1
LABEL description="A printing server (CUPS)"

RUN apt-get update && apt-get -y install cups libcupsimage2 iproute2

# Additional driver packages:
ARG PACKAGES=printer-driver-foo2zjs
RUN apt-get install -y $PACKAGES && \
	apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

VOLUME /var/log/cups
VOLUME /var/spool/cups
VOLUME /var/cache/cups
VOLUME /run/cups

ENV PORT=631 \
	CUPS_USER=admin \
	LOG_LEVEL=warn
COPY --chmod=777 <<-'START' /bin/start.sh
	#!/bin/sh
	set -ex

	useradd -G lpadmin -M $CUPS_USER
	cat /run/secrets/password /run/secrets/password | passwd -q $CUPS_USER
	
	echo 'ServerName localhost:631' > /etc/cups/client.conf

	GATEWAY=$(ip route | grep default | awk '{print $3}')
	echo "PORT $PORT
			LogLevel $LOG_LEVEL
			PageLogFormat
			ServerAlias *
			Browsing On
			BrowseLocalProtocols dnssd
			DefaultAuthType Basic
			DefaultEncryption Never
			HostNameLookups On
			WebInterface Yes
		<Location />
			Order allow,deny
			Allow from localhost
			Allow from $GATEWAY
			Allow from 192.168.1.*
		</Location>
		<Location /admin>
			Order allow,deny
			Allow from localhost
			Allow from $GATEWAY
			Allow from 192.168.1.*
		</Location>
		<Location /admin/conf>
			Order allow,deny
			Allow from localhost
			Allow from $GATEWAY
			Allow from 192.168.1.*
		</Location>" >> /etc/cups/cupsd.conf

	exec /usr/sbin/cupsd -f -c /etc/cups/cupsd.conf
START

EXPOSE $PORT 5353/udp

CMD ["/bin/start.sh"]
services:
  printer:
    container_name: printer
    build:
      context: ./services/cups
      args:
        DOCKER_BUILDKIT: 1
        PACKAGES: printer-driver-foo2zjs
    restart: unless-stopped
    environment:
      - CUPS_USER=alexander
    volumes:
      - /var/run/dbus:/var/run/dbus
    secrets:
      - source: cups-password
        target: password
    devices:
      # echo 'ATTR{idVendor}=="04e8", ATTR{idProduct}=="331a", SYMLINK+="clp_printer"' >> /etc/udev/rules.d/z21_persistent-local.rules    
      # - "/dev/clp_printer:/dev/clp_printer" # -- does not work.
      - "/dev/bus/usb/001/004:/dev/bus/usb/001/004" # -- works.
    ports:
      - 631:631 # IPP printer sharing.
    deploy:
      resources:
        limits:
          memory: 1g
secrets:
  cups-password:
    file: ./secrets/cups/password

alex-mashin avatar Jun 04 '24 10:06 alex-mashin

Not sure there is anything that we can do here, but I will see what I can find out...

michaelrsweet avatar Aug 14 '24 04:08 michaelrsweet

OK, the "/dev/clp_printer" device will never work with the CUPS USB backend anyways - libusb depends on the standard device filenames, so that's what you need to list (which as you indicate does actually work...)

michaelrsweet avatar Sep 20 '24 16:09 michaelrsweet

A dirty workaround: you can mount the whole of /dev to the container. In that case, the symlink /dev/clp_printer will work:

    volumes:
      - /var/run/dbus:/var/run/dbus
      - /dev:/dev
    devices:
      - "/dev/clp_printer:/dev/clp_printer"

Otherwise, the symlink /dev/clp_printer -> bus/usb/001/… will not be recognised as such, if even the whole of /dev/bus/usb/001 host is also mounted.

alex-mashin avatar Oct 29 '24 08:10 alex-mashin