Docker Community Forums

Share and learn in the Docker community.

Connect Docker container to host server

Hi, I developed a Node-RED dashboard that connects to an OPC UA Server over TCP that is on my host computer. I’d like to dockerise this so i’ve been following some tutorials to build my container and map the docker port 1880 to the host port 1880.

This works fine but i can’t seem to connect to my OPC UA server anymore through my to my docker container. Does anyone know how to map a port from the host to a docker conatiner so Node-RED can see the server? All the documention seems to be about mapping docker ports to the host rather than the other way around?

my server is located at opc.tcp://localhost:49500

To build my docker container, map Node-RED to port 1880 and have persistant data I use the following command:

docker run -it -p 1880:1880 -v node_data:/data --name OPC_UA nodered/node-red

I’ve tried adding the port using an additional -p tag but this doesn’t seem to work since my host sever is using that port. Using the next port also doesn’t seem to work - although on compile there are no errors.

docker run -it -p 1880:1880 -p 49500:49501 -v node_data:/data --name OPC_UA nodered/node-red

This is currently running on my windows machine but in the future i’d like to deploy to a raspberry pi.

Any help would be fantastic!
Ollie

You don’t have to map anything, you can call your server directly from your container. But remember that for the container the server is not at localhost (this is the container itself), but at its real IP address.

Use --network=“host” in your docker run command, then 127.0. 0.1 in your docker container will point to your docker host. Note: This mode only works on Docker for Linux, per the documentation.