e-alfred / nextcloud-printer

App to allow direct printing from Nextcloud through LPR/CUPS-connected printers
GNU General Public License v3.0
23 stars 9 forks source link

nextcloud-printer within docker #5

Open Mailblocker opened 4 years ago

Mailblocker commented 4 years ago

Hi, thanks for the great addon e-alfred! After some investigation I got it working for my nextcloud instance running within a docker container. I leave it here, just in case someone needs this.

Preconditions

  1. A running CUPS server with a shared printer accessable via IPP over the internal network
  2. A nextcloud docker instance

The following changes will build the docker nextcloud image based on nextcloud:fpm (if needed change the image) with the packages cups-client, cups-daemon and cups-bsd installed. Additionally a startup script (myNextcloud.sh) is added. It will start the cups service, add a remote printer (change the IP and the printer name accoringly to the CUPS server) via IPP and set this printer as the default CUPS printer. Afterwards the entrypoint.sh script of the docker nextcloud image is started.

docker compose file

...
  nextcloud:
#    image: nextcloud:fpm
    build:
      context: .
      dockerfile: myNextcloud
...

Dockerfile: myNextcloud

FROM        nextcloud:fpm
ADD     myNextcloud.sh /
RUN     apt-get update && apt-get install -y cups-client cups-daemon cups-bsd && chmod +x /myNextcloud.sh
ENTRYPOINT  ["/myNextcloud.sh"]
CMD     ["php-fpm"]

Startscript: myNextcloud.sh

#!/usr/bin/env sh
service cups start
lpadmin -p HP_M281_docker -E -v ipp://192.168.2.42:631/printers/HP_M281 -m everywhere
lpoptions -d HP_M281_docker
sh /entrypoint.sh "$@"

@e-alfred If needed feel free to add it to the documentation, I can also provide a PR.

Question: Is it possible to use lp instead of lpr as the printer command in the plugin? Doing this would not make it neccessary to install cups-bsd.

e-alfred commented 4 years ago

If you can make a PR, that would be awesome! Using lp instead of lpr might be possible but I had some permissions problems with it so I opted for lpr for now.

Mailblocker commented 4 years ago

Ah okay, could be since I'm using the plugin within a docker container the call lpr should be executed as root. Therefore I might not have any troubles with lp but others might.