Giter Club home page Giter Club logo

cups-docker's Introduction

CUPS-docker

Run a CUPS print server on a remote machine to share USB printers over WiFi. Built primarily to use with Raspberry Pis as a headless server, but there is no reason this wouldn't work on amd64 machines. Tested and confirmed working on a Raspberry Pi 3B+ (arm/v7) and Raspberry Pi 4 (arm64/v8).

Container packages available from Docker Hub and Github Container Registry (ghcr.io)

  • Docker Hub Image: anujdatar/cups
  • GHCR Image: ghcr.io/anujdatar/cups

Usage

Quick start with default parameters

docker run -d -p 631:631 --device /dev/bus/usb --name cups anujdatar/cups

Customizing your container

docker run -d --name cups \
    --restart unless-stopped \
    -p 631:631 \
    --device /dev/bus/usb \
    -e CUPSADMIN=batman \
    -e CUPSPASSWORD=batcave_password \
    -e TZ="America/Gotham" \
    -v <persistent-config-folder>:/etc/cups \
    anujdatar/cups

Note: :P make sure you use valid TZ string, this is just a joke. Also changing the default username and password is highly recommended.

Parameters and defaults

  • port -> default cups network port 631:631. Change not recommended unless you know what you're doing
  • device -> used to give docker access to USB printer. Default passes the whole USB bus /dev/bus/usb, in case you change the USB port on your device later. change to specific USB port if it will always be fixed, for eg. /dev/bus/usb/001/005.

Optional parameters

  • name -> whatever you want to call your docker image. using cups in the example above.
  • volume -> adds a persistent volume for CUPS config files if you need to migrate or start a new container with the same settings

Environment variables that can be changed to suit your needs, use the -e tag

# Parameter Default Type Description
1 TZ "America/New_York" string Time zone of your server
2 CUPSADMIN admin string Name of the admin user for server
3 CUPSPASSWORD password string Password for server admin

docker-compose

version: "3"
services:
    cups:
        image: anujdatar/cups
        container_name: cups
        restart: unless-stopped
        ports:
            - "631:631"
        devices:
            - /dev/bus/usb:/dev/bus/usb
        environment:
            - CUPSADMIN=batman
            - CUPSPASSWORD=batcave_password
            - TZ="America/Gotham"
        volumes:
            - <persistent-config-path>:/etc/cups

Server Administration

You should now be able to access CUPS admin server using the IP address of your headless computer/server http://192.168.xxx.xxx:631, or whatever. If your server has avahi-daemon/mdns running you can use the hostname, http://printer.local:631. (IP and hostname will vary, these are just examples)

If you are running this on your PC, i.e. not on a headless server, you should be able to log in on http://localhost:631

Thanks

Based on the work done by RagingTiger: https://github.com/RagingTiger/cups-airprint

cups-docker's People

Contributors

anujdatar avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

cups-docker's Issues

CUPS Fails to Detect Printer After Power Off

Currently, when the printer is turned off, cups is unable to detect it when I turn it back on.

It works fine when i restart the docker container, so I think its having trouble finding the /dev/usb/[], since it changes when the printer is reconnected container host's OS.

Not sure that I set up something wrong, or its an issue with the container.

docker-compose.yml:

services:
    cups:
        image: anujdatar/cups
        container_name: cups
        restart: always
        ports:
            - "631:631"
        devices:
            - /dev/bus:/dev/bus
            - /dev/usb:/dev/usb
        environment:
            - CUPSADMIN=admin
            - CUPSPASSWORD=password
            - TZ="Europe/Warsaw"
        volumes:
            - ./data:/etc/cups

data/printers.conf:

# Written by cupsd
# DO NOT EDIT THIS FILE WHEN CUPSD IS RUNNING
NextPrinterId 2
<Printer EPSON_L310_Series>
PrinterId 1
UUID urn:uuid:aa358d43-05a5-31db-6324-f9e9d4e078b6
Info EPSON L310 Series
Location
MakeModel Epson L310 - CUPS+Gutenprint v5.3.4
DeviceURI usb://EPSON/L310%20Series?serial=56484D4B3032353618
State Idle
StateTime 1712484122
ConfigTime 1711806586
Type 8425484
Accepting Yes
Shared Yes
JobSheets none none
QuotaPeriod 0
PageLimit 0
KLimit 0
OpPolicy default
ErrorPolicy retry-job
</Printer>

paper size issues

i've got a thermal label printer that i have working connected to my server and running from the docker image, which i can then print from my mac to...but the problem is that it's always printing the wrong size. i've got a 4x6 label that i'm trying to print and it's set to print to a 4x6 label in mac os and the default paper size on the server is set to 4x6, but it just doesn't print correctly. ever. it's printing the top of the label at the very bottom and only actually printing maybe the top inch or so at the very bottom of the label.

any ideas? i've been pulling my hair out for hours trying to figure out what i'm doing wrong and i've got nothing.

how do I map a printer through macos

I was able to map this printer through Windows 11 just fine, using "select a shared printer by name". But I'm unsure how to map this printer on my MacBook?

cannot show any printer with software

the printe have cups website
image

bud master pdf editor or other wps and any pdf software cannot detect print

you build is back
image

any pdf software canot show it

Persistance

Thanks for this useful software, I run it in a Proxmox Ubuntu VM in a Docker container. It does what Google Cloud print used to do for me. Any word on adding persistence?

Failed when build in Arch=arm32v6 (Rpi zero w)

when there was a build on raspberry pi zero w (ARCH=arm32v6)
after cloning the repository, it returns the following error.

 => CACHED [5/6] COPY entrypoint.sh /                                                                                                                              0.0s
 => ERROR [6/6] RUN chmod +x /entrypoint.sh                                                                                                                        7.0s
------                                                                                                                                                                  
 > [6/6] RUN chmod +x /entrypoint.sh:
5.351 runc run failed: unable to start container process: exec: "/bin/sh": stat /bin/sh: no such file or directory
------
Dockerfile:51
--------------------
  49 |     
  50 |     COPY entrypoint.sh /
  51 | >>> RUN chmod +x /entrypoint.sh
  52 |     
  53 |     CMD ["/entrypoint.sh"]
--------------------
ERROR: failed to solve: process "/bin/sh -c chmod +x /entrypoint.sh" did not complete successfully: exit code: 1

Enable CUPS auto discovery

I saw your attempt to enable auto-discovery in this commit added avahi-daemon, and exposed port 5353/udp for multicast dns

While that's the correct direction, the normal linux systemd work in a little more complex way.
Specifically, compare to a normal working service, you also need to start process avahi-daemon.service and cups-browsed.service

You can look here

  • /usr/lib/systemd/system/cups-browsed.service
  • /etc/systemd/system/printer.target.wants/cups.service
  • /usr/lib/systemd/system/avahi-daemon.service

As you can see, it's quite complex to start all the services using your entrypoint.

In order to accomplish that you could take a look at supervisord and tini or my prefered method s6-overlay.

With s6-overlay, you could create many services. Take a look at an example below (generated by ChatGPT)

The s6-overlay is a powerful init system designed for use with Docker containers, allowing you to manage multiple processes within a single container. Here's a basic guide on how to use s6-overlay in a Dockerfile to start multiple processes:

  1. Create a Dockerfile:

    Create a new Dockerfile for your application. Here's a basic example:

    FROM your-base-image
    
    # Install s6-overlay
    ADD https://github.com/just-containers/s6-overlay/releases/download/v2.2.0.3/s6-overlay-amd64.tar.gz /tmp/
    RUN tar xzf /tmp/s6-overlay-amd64.tar.gz -C / \
        && rm /tmp/s6-overlay-amd64.tar.gz
    
    # Add your application files
    COPY ./app /app
    
    # Add s6 service definitions
    COPY ./services /etc/services.d
    
    # Command to start s6-init
    CMD ["/init"]

    In this example, replace your-base-image with the base image you want to use, and ./app with the path to your application files.

  2. Create a services directory:

    Create a directory called services in the same directory as your Dockerfile. Inside this directory, you will define service scripts for each process you want to run.

    For example, if you want to run two processes, create files like services/app1/run and services/app2/run. The contents of these files might look like:

    # services/app1/run
    #!/usr/bin/with-contenv sh
    
    exec /app/app1
    # services/app2/run
    #!/usr/bin/with-contenv sh
    
    exec /app/app2

    These scripts will be executed by s6 when the container starts.

  3. Build your Docker image:

    Run the following command to build your Docker image:

    docker build -t your-image-name .
  4. Run your Docker container:

    Now, you can run your Docker container:

    docker run -d your-image-name

The s6-overlay will manage the specified processes, and you can scale this approach to include more services as needed. The key is to create service scripts in the services directory, and s6 will take care of starting and managing those services within the Docker container.

Printer not visible in Share folder

Hi,

I installed CUPS on TrueNas Scale, added printer and checked to share this printer but it isn't visible in Server shared folder. After investigation it looks like SAMBA is not installed and that is why it isn't visible for windows in shared folder. Will it be possible to add by default SAMBA as installed app?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.