Printing from inside a docker container

12.7k views Asked by At

With the influx of GUI applications being ported to docker, what is the best way to print to cups from inside a docker container?

NB: I am not looking to run cups from inside the container as this breaks the single service paradigm associated with docker.

1

There are 1 answers

2
Chris Daish On

Self Documenting after investigation work on how to achieve this goal.

Mounting in the cups socket worked great...ish (acroread failed to populate printers) with an Ubuntu based docker host, however this failed with a Redhat host.

...
-v /var/run/cups:/var/run/cups:ro
...

Populating the cups client.conf appeared to be a better solution.

cat /tmp/client.conf

#The ServerName directive specifies sets the remote server 
# that is to be used for all client operations. That is, it 
# redirects all client requests to the remote server. The 
# default port number is 631 but can be overridden by adding
# a colon followed by the desired port number to the value.
# The default is to use the local server ("localhost").
ServerName <DOCKER0 BRIDGE IP>

and the docker launch argument:

...
-v /tmp/client.conf:/etc/cups/client.conf:ro \
...

I also had to ensure the cups server would bind to the docker0 bridge and allow other devices to access the cups server:

...
Listen *:631
...
<Location />
  Order allow,deny
  Allow all
</Location>
...

Once cups had restarted and the cups client.conf passed into the container I was able to print as expected.