2023-12-07 17:42:13 +01:00
This Image is built and used by [prind ](. ).
2022-07-08 00:29:49 +02:00
# Klipper packaged in Docker
## What is Klipper?
>Klipper is a 3d-Printer firmware. It combines the power of a general purpose computer with one or more micro-controllers. See the features document for more information on why you should use Klipper.
_via https://www.klipper3d.org/_
## Usage
2023-06-07 20:52:02 +02:00
As Klipper needs access to your hosts devices, it is recommended to run it in privileged mode and mount your hosts `/dev` directory.
It is possible to run klipper in unprivileged mode but this will break as soon as your MCU resets and gets assigned a new Device name by your hosts OS. See [this issue ](https://github.com/mkuf/prind/issues/77 ) for reference.
2022-07-08 00:29:49 +02:00
### Standalone
2023-06-07 20:52:02 +02:00
Create a configfile `printer.cfg` and a directory `run` , then run the container.
Point your GCODE-Sender to `klipper.tty` within the `run` directory.
2022-07-08 00:29:49 +02:00
#### Run
```bash
docker run \
--privileged \
-v /dev:/dev \
2022-10-18 20:49:48 +02:00
-v $(pwd)/run:/opt/printer_data/run \
-v $(pwd)/printer.cfg:/opt/printer_data/config/printer.cfg \
2022-07-08 00:29:49 +02:00
mkuf/klipper:latest
```
#### Compose
```yaml
services:
klipper:
image: mkuf/klipper:latest
privileged: true
volumes:
- /dev:/dev
2022-10-18 20:49:48 +02:00
- ./printer.cfg:/opt/printer_data/config/printer.cfg
- ./run:/opt/printer_data/run
2022-07-08 00:29:49 +02:00
```
### With Moonraker
2023-06-07 20:52:02 +02:00
If you intend to use Klipper together with Moonraker, they need to share a common directory in which the socket may be located.
2022-07-08 00:29:49 +02:00
Further Info on how to use the Moonraker Image can be found in its [README.md ](../moonraker/README.md )
2022-10-18 20:49:48 +02:00
Create `moonraker.conf` and `printer.cfg` as well as the directories `run` and `gcode` , then run the containers.
2022-07-08 00:29:49 +02:00
#### Run
```bash
docker run \
2023-06-07 20:52:02 +02:00
--privileged \
-v /dev:/dev
2022-10-18 20:49:48 +02:00
-v $(pwd)/run:/opt/printer_data/run \
-v $(pwd)/gcode:/opt/printer_data/gcodes \
-v $(pwd)/printer.cfg:/opt/printer_data/config/printer.cfg \
2022-07-08 00:29:49 +02:00
mkuf/klipper:latest
docker run \
2022-10-18 20:49:48 +02:00
-v $(pwd)/run:/opt/printer_data/run \
-v $(pwd)/gcode:/opt/printer_data/gcodes \
-v $(pwd)/moonraker.conf:/opt/printer_data/config/moonraker.conf \
2022-07-08 00:29:49 +02:00
-p 7125:7125 \
mkuf/moonraker:latest
```
#### Compose
```yaml
services:
klipper:
image: mkuf/klipper:latest
2023-06-07 20:52:02 +02:00
privileged: true
2022-07-08 00:29:49 +02:00
volumes:
2023-06-07 20:52:02 +02:00
- /dev:/dev
2022-10-18 20:49:48 +02:00
- ./printer.cfg:/opt/printer_data/config/printer.cfg
- ./run:/opt/printer_data/run
- ./gcode:/opt/printer_data/gcodes
2022-07-08 00:29:49 +02:00
moonraker:
image: mkuf/moonraker:latest
ports:
- "7125:7125"
volumes:
2022-10-18 20:49:48 +02:00
- ./moonraker.conf:/opt/printer_data/config/moonraker.conf
- ./run:/opt/printer_data/run
- ./gcode:/opt/printer_data/gcodes
2022-07-08 00:29:49 +02:00
```
## Defaults
|Entity|Description|
|---|---|
|User| `klipper (1000:1000)` |
|Workdir|`/opt` |
|Entrypoint|`/opt/venv/bin/python klipper/klipper/klippy.py` |
2022-10-18 20:49:48 +02:00
|Cmd|`-I printer_data/run/klipper.tty -a printer_data/run/klipper.sock printer_data/config/printer.cfg` |
2022-07-08 00:29:49 +02:00
## Ports
none
## Volumes
|Volume|Description|
|---|---|
2022-10-19 13:21:20 +02:00
|`/opt/printer_data/run` | Default Location for runtime Files generated by Klipper. <br>Namely `klipper.tty` , the emulated Serial device <br>and `klipper.sock` , the unix socket that is used for communation with moonraker |
|`/opt/printer_data/config` |Config directory to host `printer.cfg` |
|`/opt/printer_data/gcodes` |Stores GCODE Files to be used by Klipper|
|`/opt/printer_data/logs` |Log directory for Klipper and Moonraker|
2022-07-08 00:29:49 +02:00
## Tags
|Tag|Description|Static|
|---|---|---|
2024-02-22 22:43:56 +01:00
|`latest` |Refers to the most recent runtime Image for klippy.|May point to a new build within 24h, depending on code changes in the upstream repository.|
|`<git description>` <br>eg: `v0.12.0-114-ga77d0790` |Refers to a specific [git description ](https://git-scm.com/docs/git-describe#_examples ) in the upstream repository. eg: [Klipper3d/klipper:v0.12.0-114-ga77d0790 ](https://github.com/Klipper3d/klipper/commit/a77d07907fdfcd76f7175231caee170db205ff04 )|Yes|
2023-06-17 12:48:52 +02:00
|`*-tools` |Refers to Debian Image containing all Tools necessary to Build the Microcontroller code for Klipper|Yes|
|`*-hostmcu` |Refers to the runtime Image for klipper_mcu.|Yes|
2022-07-08 00:29:49 +02:00
## Targets
|Target|Description|Pushed|
|---|---|---|
|`build` |Pull Upstream Codebase and build python venv|No|
|`build-simulavr` |Based on `mcu` : Pull and Build simulavr for klipper. Used for testing without Hardware.|No|
2023-06-17 12:48:52 +02:00
|`build-hostmcu` |Based on `mcu` : Build the klipper_mcu binary|No|
|`run` |Default runtime Image for klippy|Yes|
|`tools` |Build Tools for MCU code compilation|Yes|
2024-11-11 23:03:40 +01:00
|`hostmcu` |Runtime Image for the klipper_mcu binary|Yes|
## Healthcheck
2024-11-24 11:45:15 +01:00
`/opt/health.py` is available to check the health of the container.
> Be aware that enabling health checks in docker may increase CPU usage drastically.
> In tests, cpu usage of the container was doubled when executing the healtch check every 30s and increased sixfold when executing every 5s.
> This may lead to resource shortages on low powered host and unwanted behaviour
2024-11-11 23:03:40 +01:00
The script does the following:
* queries klippers `info` endpoint via its unix socket
* Checks if state is `ready`
2024-11-24 11:45:15 +01:00
* If one of the above requirements is not `ready` , the script exits with a failure state to indicate the container is unhealthy
Compose example:
```yaml
services:
klipper:
healthcheck:
test: ["python3", "/opt/health.py"]
interval: 30s
```