DEV Community

Joe Block
Joe Block

Posted on • Originally published at unixorn.github.io

Use a Raspberry Pi as a print server

I have an old HP 4050N. For a variety of reasons, I want to have it behind a print server instead of having our laptops print directly to it. Here's how I set that up.

Prerequisites

  • A Raspberry Pi (or honestly any Linux box) running docker. I like the Raspberry Pi and Odroid HC2 for this sort of thing because they have very low power consumption.
  • A printer that is supported by CUPS

Setup

There are several docker images out there you can use, I made one (the source is on github at unixorn/docker-cupsd) because I wanted one that was multi-architecture - mine has AMD64, ARM7 and ARM64 all baked into the same image so you don't have to change the image label based on what system you're running it on. It works fine on Raspberry Pi, Odroids and Intel servers.

The unixorn/cupsd image is a bit on the large side because I crammed a lot of printer drivers into it, you may want to look for docker images that only support single printer families.

We're going to store printers.conf in a directory outside the container so that we don't lose our printer configuration every time we upgrade our container.

I run the cupsd server on an Odroid HC2 because I have /var/lib/docker on the 2TB drive attached to it. I could have put it on one of the Raspberry Pis in my cluster, but didn't want it spooling print jobs and causing excessive wear on a rPi's microSD card.

  1. Make a directory to store your printer configuration. We'll use /docker/cupsd/etc
  2. export CUPSD_DIR='/docker/cupsd/etc'
  3. touch $CUPSD_DIR/printers.conf
  4. Run the cupsd server with
sudo docker run -d --restart unless-stopped \
  -p 631:631 \
  --privileged \
  -v /var/run/dbus:/var/run/dbus \
  -v /dev/bus/usb:/dev/bus/usb \
  -v "$CUPSD_DIR/printers.conf:/etc/cups/printers.conf" \
  unixorn/cupsd
Enter fullscreen mode Exit fullscreen mode

You can now connect to http://SERVER:631 and add printers using the web UI.

When adding the printers to your Mac, select Internet Printing Protocol and put in the IP or DNS name of your print server machine.

The queues are printers/printername, not printername.

Top comments (0)