Error in running .sh file in Dockerfile

Hello! I am trying to run a .sh file in a Docker container, I keep getting the error at the bottom does soemone know why :frowning: I want to use virtual can to make receive some messages, plase help I am new with .sh files on Docker! Thank you!

Dockerfile

FROM docker.deere.com/python:3.8-alpine
WORKDIR /app
COPY ./requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY ./ /app
ADD setup-vcan.sh /app/setup-vcan.sh
RUN chmod +x /app/setup-vcan.sh
ENTRYPOINT [“sh”,“/app/setup-vcan.sh”]
CMD [“python”, “./threading_can_bus.py”]

Inside .sh:

#!/bin/bash
ip link add dev vcan0 type vcan
ip link set up vcan0

ip link add dev vcan1 type vcan
ip link set up vcan1

ip link add dev vcan2 type vcan
ip link set up vcan2

error:

❯ docker run -it can_bus
ip: RTNETLINK answers: Operation not permitted
ip: ioctl 0x8913 failed: No such device
ip: RTNETLINK answers: Operation not permitted
ip: ioctl 0x8913 failed: No such device
ip: RTNETLINK answers: Operation not permitted
ip: ioctl 0x8913 failed: No such device

It seems your vcan is not available inside the container. Maybe you need to add some special parameters to mount it into the container?

The script does not make sense during image build, as it is a runtime problem, and not a problem that can be solved during image build.

Even during runtime it’s going to be “special”, as you would need to pass the devices into the container to work with them.

Update: my bad, I thought the scripts is executed during build. Instead, it’s executed as entrypoint script.
Of course, you still need to pass the devices into the container, and make the network devices available to work (if it will work at all).

Furthermore, when your Dockerfile specifies an ENTRYPOINT and CMD instruction, the value of the CMD instruction will be arguments to your entrypoint script, but your entrypoint script doesn’t handle the arguments. It would handle them if you add exec "$@" as last line in your script.