1
votes

I have dockerized a simple OPC UA server. When I run it locally, I am capable of connecting to the server without problems. However, when I run the server in a Docker container the client refuses to connect. Further, when I try to set the endpoint for the server as opc.tcp://localhost:4840, the server will not bind to the address when it is ran inside a container. The endpoint opc.tcp://127.0.0.1:4840 must be used. This is not an issue when running the server locally. The following library is used to implement the server https://github.com/FreeOpcUa/python-opcua and the client used is https://github.com/FreeOpcUa/opcua-client-gui.

I have tried to set different endpoints without any luck.

The server implementation is:

from opcua import Server, ua

server = Server()
server.set_endpoint('opc.tcp://127.0.0.1:4840')
server.set_security_policy([ua.SecurityPolicyType.NoSecurity])
server.start()
try:
    while True:
        i = 1
finally:
    server.stop()

The 'Dockerfile' exposes the following port EXPOSE 4840. The Docker run command is

docker run --rm --name server -p 4840:4840 opcua
2

2 Answers

0
votes

You server in container is only listening to 127.0.0.1, hence only accepting connection from inside the container:

server.set_endpoint('opc.tcp://127.0.0.1:4840')

You should listen to all hosts such as:

server.set_endpoint('opc.tcp://0.0.0.0:4840')
0
votes

you need to use --network host in your docker run command , since localhost on the conatiner is not your host