title: Connect to an OPC UA server running inside a container
body: <p>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 <a href="https://github.com/FreeOpcUa/python-opcua" rel="nofollow noreferrer">https://github.com/FreeOpcUa/python-opcua</a> and the client used is <a href="https://github.com/FreeOpcUa/opcua-client-gui" rel="nofollow noreferrer">https://github.com/FreeOpcUa/opcua-client-gui</a>.</p>
  
  <p>I have tried to set different endpoints without any luck.</p>
  
  <p>The server implementation is:</p>
  
  <pre><code>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()
  </code></pre>
  
  <p>The 'Dockerfile' exposes the following port <code>EXPOSE 4840</code>. The <code>Docker run</code> command is</p>
  
  <pre><code>docker run --rm --name server -p 4840:4840 opcua
  </code></pre>