Docker Community Forums

Share and learn in the Docker community.

How to EXPOSE COM PORT

docker

(Labskfx1234) #1

Hi,

I am new to docker and I tried to run a python script in docker and got the following error

Traceback (most recent call last):
File “./script.py”, line 18, in
ser=serial.Serial(’/dev/ttyS1’,baudrate=9600,timeout=0)
File “/usr/local/lib/python3.6/site-packages/serial/serialutil.py”, line 240, in init
self.open()
File “/usr/local/lib/python3.6/site-packages/serial/serialposix.py”, line 268, in open
raise SerialException(msg.errno, “could not open port {}: {}”.format(self._port, msg))
serial.serialutil.SerialException: [Errno 2] could not open port /dev/ttyS1: [Errno 2] No such file or directory: ‘/dev/ttyS1’

My Dockerfile is as follows:

FROM python:3

ADD script.py /

RUN pip install pystrich

RUN pip install pyserial

CMD [ “python”, “./script.py” ]

Guessing that the error is caused because the port is not exposed ; how do I expose port ttyS1 ?
Thanks.