|
1 |
| -This is a docker image for the Unix/Linux port of CircuitPython. It can be useful for running unit tests or trying out CircuitPython when you don't have access to a board. |
| 1 | +# CircuitPython Container |
2 | 2 |
|
3 |
| -A build for this image is available on Docker Hub at: https://hub.docker.com/r/jphalip/circuitpython-linux |
| 3 | +This is a container image for the Unix/Linux port of CircuitPython. It can be useful for running unit tests or trying out CircuitPython when you don't have access to a board. |
| 4 | + |
| 5 | +## Getting Started |
| 6 | +### REPL |
| 7 | +To enter the REPL, simply run the container. |
| 8 | +```text |
| 9 | +$ docker run -it ghcr.io/rgrizzell/circuitpython |
| 10 | +CircuitPython 9.0.5 on 2024-05-22; linux [GCC 12.2.0] version |
| 11 | +Use Ctrl-D to exit, Ctrl-E for paste mode |
| 12 | +>>> |
| 13 | +``` |
| 14 | + |
| 15 | +### Inline |
| 16 | +Inline scripts can be passed using the `-c` flag. |
| 17 | +```text |
| 18 | +$ docker run -it ghcr.io/rgrizzell/circuitpython -c 'import sys; print(sys.version)' |
| 19 | +3.4.0; CircuitPython 9.0.5 on 2024-05-22 |
| 20 | +``` |
| 21 | + |
| 22 | +### Files |
| 23 | +Files can be run by mounting the directory into `/app` and passing the file name to the container. |
| 24 | +```text |
| 25 | +$ cat version.py |
| 26 | +import sys |
| 27 | +print(sys.version) |
| 28 | +
|
| 29 | +$ docker run -v $PWD:/circuitpy -it ghcr.io/rgrizzell/circuitpython version.py |
| 30 | +3.4.0; CircuitPython 9.0.5 on 2024-05-22 |
| 31 | +``` |
| 32 | + |
| 33 | +## Advanced Usage |
| 34 | +### mpy-cross |
| 35 | +The `mpy-cross` utility is available as well. To access it, include the `--entrypoint=mpy-cross` option when starting the container. |
| 36 | + |
| 37 | +To compile a file to bytecode format for a target architecture, mount the code directory with `-v $PWD:/circuitpy` and then pass the compilation options at the end: `-march=xtensa version.py` |
| 38 | + |
| 39 | +```text |
| 40 | +$ docker run -v $PWD:/circuitpy --entrypoint=mpy-cross -it ghcr.io/rgrizzell/circuitpython -march=xtensa version.py |
| 41 | +$ ls version.* |
| 42 | +-rw-r--r--. 1 rgrizzell rgrizzell 58 May 22 13:38 version.mpy |
| 43 | +-rw-r--r--. 1 rgrizzell rgrizzell 30 May 22 12:55 version.py |
| 44 | +``` |
| 45 | + |
| 46 | +### Filesystem |
| 47 | +The runtime container is based on Debian Slim, and the underlying filesystem can be access by adding `--entrypoint=/bin/bash` when starting the container. |
| 48 | +```text |
| 49 | +$ docker run --entrypoint=/bin/bash -it ghcr.io/rgrizzell/circuitpython |
| 50 | +circuitpy@1d66ff3d565b:~# |
| 51 | +circuitpy@1d66ff3d565b:~# ls / |
| 52 | +bin boot circuitpy dev etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var |
| 53 | +``` |
| 54 | + |
| 55 | +## Building |
| 56 | +Building the image is straight-forward. |
| 57 | +```text |
| 58 | +docker build -t circuitpython . |
| 59 | +``` |
| 60 | + |
| 61 | +Specific CircuitPython versions can also be built by passing a build argument. |
| 62 | +```text |
| 63 | +docker build -t circuitpython:9.0.4 --build-arg="VERSION=9.0.4" . |
| 64 | +``` |
0 commit comments