Docker Community Forums

Share and learn in the Docker community.

Can't share network interface between host machine and docker container

For some reason, I can’t get my Host machine’s network to be shared with my docker container. Specifically, I am trying to bring up a CAN interface sudo slcand -o -c -s0 /dev/ttyACM0 can0. The problem is this. I can bring it up on my host machine, however, when I run my container, it can’t find the device. However, my Host machine shouldn’t need to bring up the interface, as in my docker container, I have a bash script that will deal with bring up the can0 interface

EDIT: If it makes a difference I am trying to do this on a Raspberry Pi.

I am using this command to run my container:

docker run -t -i --device=/dev/ttyACM0

Then, I have a bash script which deals with bringing the can0 interface. However, when I do the run command, I print out the ifconfig in my bash script and neither the can0 or wlan0 interfaces appear.

Since the bash script, attempts to bring up the can0 interface, it fails and gives me this error:

OSError: [Errno 19] No such device

I have no idea what I am doing wrong. Has anyone else ran into this issue? Here is what my docker file looks like:

FROM ubuntu:latest
COPY requirements.txt /
RUN apt-get update
RUN apt-get install -y python3-pip
RUN pip3 install -r requirements.txt
RUN apt-get install -y can-utils
RUN apt-get install -y net-tools
RUN useradd -m docker && echo "docker:docker" | chpasswd && adduser docker sudo
USER docker
COPY ./ /generator-data-tools
WORKDIR /generator-data-tools
ENTRYPOINT ["/bin/bash"]
CMD ["/generator-data-tools/"]

And my bash script:

echo "Configuring CAN network"
ls /dev/data-streaming
slcand -o -c -s0 /dev/ttyACM0
ifconfig; ifconfig can0 up
echo "Starting to stream data"
python3 ./

Thanks to all of those who reply in advance.