OpenPrinting / cups

OpenPrinting CUPS Sources
https://openprinting.github.io/cups
Apache License 2.0
1.05k stars 187 forks source link

CUPS does not recognise symlinks to devices in Docker #973

Closed alex-mashin closed 1 week ago

alex-mashin commented 4 months ago

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 <alex_mashin@list.ru>
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
michaelrsweet commented 1 month ago

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

michaelrsweet commented 1 week ago

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...)