Help with CUPS and dockerfile

After trying for hours I am finally asking for help. I am using Paperless-NGX in my small business. I have it automatically pulling attachments from an email address. All is working fine. I am trying to incorporate CUPS into the container to automatically print certain attachments. I have everything set up and configured AND working. However I have to connect to the console of the container when it starts and run “service cups start”. Everything I have tried to have the service start when the container starts, breaks it and won’t let the container completely start.

This is my dockerfile:
FROM Package paperless-ngx · GitHub
RUN apt-get update &&
apt-get -y install cups cups-pdf cups-client

#CMD service cups start ; while true ; do sleep 100; done;
#CMD service cups start && touch /var/log/cups/error.log && tail -F /var/log/cups/error.log
CMD service cups start
#ENTRYPOINT service cups start && /bin/bash

You can see everything i have tried to get it working. If I only leave the RUN uncommented the container will build, and I can connect to the console to start the CUPS service.

I am semi new to Docker. Especially the more advanced concepts. Any guidance would be helpful.

I apologize if this is in the wrong section.

Thank you in advance.


the Docker-way is to start one command per container in the foreground (not as a service; not in the background). When this foreground-process ends Docker knows that this container died (and -if configured to do so- can restart this container).
So if you start CUPS in the background (=as a service) within the container there is no foreground-process and the container will die immediately. :frowning:

As a dirty workaround you can start CUPS as a service and run a never-ending command in the foreground (i.e. tail -f /dev/null). But this way Docker will never know if your CUPS-service is still running. Docker will only know that the tail ... is still running.
The clean way would be to start CUPS in the foreground.

How would I accomplish this if I already have a container that is running and working fine? I need it to be able to issue lp commands to print to a remote CUPS server, which requires having CUPS running. Would I need to start a CUPS container and somehow have my paperless container trigger and lp command on the CUPS container? I apologize for my ignorance. My experience with docker is mainly only applications that use a docker-compose file and not having to build and image and have extra services running.

Please be more precise what you have already done (which container is already started) and tested and what exactly should be done (i.e. “container A running a python-script should run a lp-command within container B running the CUPS-service to print something on a printer”).

I would go for having one container running CUPS and one container running the CUPS-client (which is you paperless-ngx-container).

For the CUPS-service you can go for already existing images or at least see how they managed to start cups within a container.
An example might be Docker Hub with its source (including the Dockerfile) beeing at dockerfiles/cupsd at master · olbat/dockerfiles · GitHub

Within the paperless-ngx-container you can use the lp-command (maybe needed to be installed) to print to the other container running the CUPS-service (instead of invoking the lp-command diretly within the CUPS-container).
May this link helps for this task: linux printing remotely with lp command to cups server not working - Super User

That got me pointed in the right direction. Thank you.