Serial device not available at Container deploy

My Dockerfile runs a script at RUN time, when the container is deployed. Here this script reads values from Serial devices passed from HostOS.

I get the following error: [Errno 2] could not open port /dev/ttyWCH0. No such file or director. The device file is not available at the start of container.

But once the conatiner loads up, if I run the script again, it works. There is some latency or container is loading the device nodes way too late.

Is this script runs IN dockerfile?

So you have something like



This script will not work when container is DEPLOYED. This script will run when image is BUILDING
If you have this setup you should move this directive to some entrypoint

I fail to understand why script will not work when the container is deployed.

You are right, the directive to run the script is declared thus in the Dockerfile.

RUN ./

Here with in the script is a call to read the Serial devices.

How to redesign so that: “move this directive to some entrypoint” is fulfilled?

Dockerfile is used to create Image
Image is not a runtime, is just a sillicon form for the containers

Balena builder that is building your image definitely doesn’t have your serial device
Run command is running during build, not deploy

After image is builded -> your fleet (device) is downloading this update, and creates containers from builded image, and now is the moment when the script should run

You should move any directive related to your device onto entrypoint script/program




COPY /entrypoint
ENTRYPOINT ["/bin/bash", "/entrypoint"]

Check the link

Docker image is an immutable (unchangeable) file that contains the source code, libraries, dependencies, tools, and other files needed for an application to run.

Due to their read-only quality, these images are sometimes referred to as snapshots. They represent an application and its virtual environment at a specific point in time. This consistency is one of the great features of Docker. It allows developers to test and experiment software in stable, uniform conditions.

Since images are, in a way, just templates , you cannot start or run them. What you can do is use that template as a base to build a container. A container is, ultimately, just a running image. Once you create a container, it adds a writable layer on top of the immutable image, meaning you can now modify it.

1 Like