Add devices to an already running container

Hello,
Is there a way to add devices to a container without having to build it again? In the docker-compse.yml we add devices like /dev/ttyS0 so we can access it from the container. I would like to do this without having to rebuild my container. I’m wondering if this is even possible. I tried editing hostconfig.json but when I restart the container all the changes get reverted to the original copy of the file.

I couldn’t find a way to do this using the supervisor api too.

Hi,

There is a hacky way to do this in docker; you might have some luck doing the same in Balena.

The real question is why you don’t want to rebuild your container though.

Have you considered setting ENV UDEV=1 to add all of /dev to your container? Maybe not a long term solution but could save you some rebuilding for the time being.

1 Like

privileged: true will map all devices in /dev into your container if they are present when it starts. To support removable devices you will also need to run UDEV in your container, which can be done by setting the UDEV environment variable as @hraftery has stated if you are using a balena base image.

Hi Ahmed,
Let us know if Heath’s suggestion worked for you. With udevd running inside your container, not only should you see /dev/* devices in the container, but also be able to set udev rules to perform specific actions when /dev/ttyS* devices are detected. Make sure you copy your .rules files to /etc/udev/rules.d/. That is necessary if you want udev to use the rules.

Hope that helps.
Please let us know if you need help with anything else.

Thanks and regards,
Pranav