Sunday, October 2, 2016

Setting up a CUPS server with Docker on a Synology NAS for my Brother printer

My Brother Printer made for Windows

I made the unfortunate mistake of purchasing a cheap brother printer, the Brother HL-L2300D, which is USB only. And not only is it a USB printer, it is a Winprinter which makes it very limited in anything other than Windows. The laser printer is great for printing, but purchasing the cheapest feature-limited version was a bad decision. If I could go back in time, I would tell myself to purchase a Brother network printer and save myself the trouble and hassle trying to network share a USB printer. I encourage you to do the same. But if you are reading this page, you probably made the same mistake I did, so read on...

Since I have my Synology DS916+, which supports acting as a print server, I wanted to use that in order to share my printer across my networked devices. Unfortunately, Synology is very limited in what USB printer it supports. The Synology support list is very small with only a few Brother printers approved. Winprinters, or technically GDI printers, have little support outside of Windows. But wait a minute, Brother provides linux drivers, no? Why not just install that on the Synology NAS?

The Brother linux drivers are not easily installed on Synology due to the different platform and library requirements not available, although it is linux. The solution that remains is using those Brother linux drivers on a Docker container with an actual linux framework that is compatible with the drivers.

Preparing the Synology NAS

Easy Bootstrap Installer

The first thing I set up was the Easy Bootstrap Installer, which provides the ipkg structure for installing linux packages. The easiest way is adding the source to your Package Source under the Package Center settings. Easy Bootstrap Installer should now be available to install from the Community package list.

Once I SSH into the machine, ipkg should be available from /opt/bin/ipkg

Install lsusb with ipkg

We need lsusb in order to determine the device address of the printer for Docker to access. A simple command ipkg install usbutils is all that is needed in order to install lsusb.

Docker Container docker-debian-cups

I found the Docker container docker-debian-cups to be a good starting point for this setup.

Docker Container Files

Brother Driver Installer

The Brother Driver Installer will be executed every time the Docker container is started, so it needs to be somewhere accessible. I downloaded the linux installer script linux-brprinter-installer-2.0.0-1 from the Brother website and placed it under /volume1/docker/cups which is the directory that will be mounted on the Docker container. This script is universal, which should work with any Brother printer.

Avahi Config Files for AirPrint

If you are not interested in AirPrint, you can skip this step. Since I have many Apple products in my home, I really wanted AirPrint set up and Avahi provides this service. In the directory /volume1/docker/cups I placed two files:

My Docker Startup Bash Script

I created a Bash script that I can execute every time I want to run the cups docker and have everything set up automatically. Let's break down the script:


# Stop CUPSD if it is running
echo "Stopping cupsd on Synology..."
/usr/syno/sbin/synoservicecfg --hard-stop cupsd

# Get Printer location
echo "Getting printer info..."
BUS=$(/opt/sbin/lsusb|grep Brother|awk '{print $2}')
DEV=$(/opt/sbin/lsusb|grep Brother|awk '{print $4}')

# Stop Container
echo "Stopping current container..."
/usr/local/bin/docker kill cups-server
/usr/local/bin/docker rm cups-server

# Run Docker
echo "Running container..."
containerID=$(/usr/local/bin/docker run -d -p 631:631 -p 5353:5353 --name cups-server --net=host --device=$PRINTER -v /volume1/docker/cups/:/home/print -v /volume1/docker/cups/avahi-daemon.conf:/etc/avahi/avahi-daemon.conf -v /volume1/docker/cups/AirPrint-HLL2300D.service:/etc/avahi/services/AirPrint-HLL2300D.service olbat/docker-debian-cups)

# Run Setup script
echo "Executing container setup script..."
/usr/local/bin/docker exec $containerID /bin/sh -c "/home/print/" &

echo "Done!"

exit 0

The first part is stopping the cups daemon that Synology includes as part of it's DSM system. The next part uses the lsusb program we installed earlier in order to grab the printer device address to pass to Docker. The third section stops any currently running cups Docker container that may already be running. The docker execution command grabs the container ID as it launches the container olbat/docker-debian-cups. Two ports are forwarded from the container, 631 which is used for cups and 5353 which is used for Avahi services. The device address from $PRINTER is passed on to the container. Other than the home directory link /volume2/docker/cups/ to /home/print, the rest map the Avahi config files that were mentioned previously.

If you are not needing Avahi, you can safely strip out those parts meant for Avahi setup.

Finally, the script /home/print/ is executed within the container which does the debian setup.

Container Setup Script

The setup script /home/print/ is ran from within the Docker Container to install the Brother drivers and also install/setup Avahi for Airprint.


echo "Running apt-get update/upgrade..."
apt-get update

echo "Installing Brother install requirements..."
apt-get install lib32gcc1 libc6-i386 lib32stdc++6 -y

echo "Running Brother printer setup..."
printf 'y\nn\nn\n' | /home/print/linux-brprinter-installer-2.0.0-1 HL-L2300D

echo "Enabling printer sharing for CUPS..."
cupsctl --share-printers
cupsctl --remote-admin

echo "Installing Avahi..."
DEBIAN_FRONTEND=noninteractive apt-get install avahi-daemon -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold"

echo "Starting Avahi..."
/etc/init.d/avahi-daemon start

We install some required libraries for the Brother drivers which do not come standard in the container. We then execute the Brother install script from the /home/print directory which is mounted to the Synology /volume1/docker/cups side. I set it to install the drivers for HL-L2300D. If you have a different printer, here is where you would place it's proper name. CUPS is then set to allow printer sharing and remote admin access. Finally, Avahi is installed and started for AirPrint.

Verification through CUPS page

Now if the initial script /volume1/docker/cups/ is executed, everything should successfully start. If you navigate to port 631 of your Synology NAS address,, you should see the CUPS server page and the Printer section should have your printer set up and ready.

I can now successfully see and print from my Windows, macOS and Apple mobile devices to my Brother USB printer hooked up to my Synology NAS. One issue that this cheap Winprinter has is that eventually it stops responding overnight and will no longer print. So what I needed to do was have the Task Scheduler execute every night in order to keep my printer working.

Hopefully using this guide you too can configure your Synology NAS to act as a CUPS print server.


  1. Works pretty well with Brother printer driver after contacting brother printer contact number. The only minor problem I have for the moment is that the margins are larger than announced.

  2. Devops has devops complete tutorial to teach various online courses to the young generation from their homes. Log on to our site and ask countless devops engineer interview questions without paying any cost.And for Courses, Get 175$ devops complete course at only 10$ [limited time discount]
    Discount link:

    Coupon Code: MAXIMUS10

  3. My internal Synology CUPS keeps restarting after some time. How can i stop it once and forever?


  4. That is nice article from you , this is informative stuff . Hope more articles from you . I also want to share some information about devops tutorial

  5. I set this up but i am having trouble it automatically adding the printer to the CUPS. It just never shows up on the print, manually adding it does work.

  6. dude after 4 days solid with no luck, this tutorial was just a massive help. I am using a dell c1765 and can confirm both airprint and server printer work like a bleeding charm. There are some changes that were needed. Luckily the latest cups has the dell driver too so didn't need to mess with that either.

    Massive thanks again.

  7. To confirm I had it working with both USB and Networked so yay!

  8. yacht charter in Goa Embark on an unforgettable voyage on a luxury yacht with Marine Asia, the leading yacht charter company in the Goa. Available for both daily and hourly rent, we own the yachts showcased by Backed by a professional crew with more than 20 years of sailing experience, our yacht rental service in Goa aims to deliver the ultimate yachting experience with professionalism, security, and unparalleled luxury.

  9. kids birthday party characters Rent Party Characters bringing them to life! Hire our amazing performers for kid's parties in all of Miami Dade, Broward, and Palm Beach Fl.

  10. As soon as I turn off the printer and turn it on again, the CUPS server does not recognize the printer anymore and I have to start the script again in order to setup up the printer again. Does someone has a solution for it?