Containerization
Docker on Linux
The text below shows how you can use (code of) the ICOtronic package in a Docker container on a Linux host. The description on how to move the interface of the Docker container is an adaption of an article/video from the “Chemnitzer Linux-Tage”.
Creating a Docker Image
To create a Docker image that contains ICOtronic just install the package with pip inside your Dockerfile. We recommend that you use a virtual environment to install the package. For an example, please take a look at our Dockerfile.
Building the Docker Image
If you do not want to create a Dockerfile yourself, you can build an image based on our Docker example file. To do that, please run the following command in the root of the repository:
docker build -t mytoolit/icotronic -f Docker/Dockerfile .
Using ICOtronic in the Docker Container
Run the container (Terminal 1)
Open a new terminal window
Open a shell in the Docker container
docker run --rm -it --name icotronic mytoolit/icotronic
Move the CAN interface into the network space of the Docker container (Terminal 2)
export DOCKERPID="$(docker inspect -f '{{ .State.Pid }}' icotronic)" 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
Note: Alternatively you can also add the option
--network hostto the Docker command from step 1. Please check out the Docker documentation to learn more about the consequences of using this option.Run a test command in Docker container (Terminal 1) e.g.:
icon list