Script and Dockerfile
to test basic CAN communication with the ICOtronic system
Note: the Docker container requires a Linux host, since we need a way to “connect” the CAN adapter to the Docker container.
- Hardware:
- Peak CAN adapter
- Power Injector
- Stationary Transceiver Unit (STU)
- Software:
- Docker (Linux host)
Please run the following command in the root of the repository:
docker build -t icocantest .
Below we will describe two different options to “connect” the CAN adapter to the running container:
- Using host networking
- Using network namespaces
-
Run Docker container:
docker run --rm --network host -it --name icocantest icocantest
-
Run script inside Docker container:
python cantest/test.py
-
Run Docker container:
docker run -itd --rm --name icocantest icocantest
-
Map CAN adapter into Docker container
export DOCKERPID="$(docker inspect -f '{{ .State.Pid }}' icocantest)" sudo ip link set can0 netns "$DOCKERPID" sudo nsenter -t "$DOCKERPID" -n ip link set can0 type can bitrate 1000000 sudo nsenter -t "$DOCKERPID" -n ip link set can0 up
-
Execute script:
docker exec icocantest python cantest/test.py
-
Cleanup:
docker stop icocantest