Docker Community Forums

Share and learn in the Docker community.

Connect to Host Ports from a service when binding is used


(Pankajkgoel) #1

Hello All:

We have bunch of services using docker compose. The services have a common network and are able to communicate with each other. We also have port bindings on the services which we access via HOST ports.

We now want to connect to a host port from the containers which has a tunnel into another server. We get a connection refused while connecting to the host port. Cannot use the port binding since the port is already in use on the hist side.

This seems to be a network/firewall issue on the host. Looked at iptables, which may be dropping the connection. We do not want to add the rules to firewall. Instead would like to configure via docker compose if there is any configuration which allows. The host is a linux ubuntu distribution.

Appreciate any inputs or feedback.

Thanks,
PG


(Mrdelorenzi) #2

I think you will have to show what you tried, and what error you got.


(Pankajkgoel) #3

We have a network shared across all docker containers defined using:
networks:
default:
external:
name: xyz

We also have ports mapped like the below on some of the services defined in compose.
ports:
9000:8000

When we connect to host port say, 9500 from container, we get connection refused. 9500 is open port on host. tcpdump captures the packets which are dropped.


(Mrdelorenzi) #4

Why connect to host port from another container? They are for thinks outside of the container.

Port 9500 is not mentioned you have only 9000 as a host port, and 8000 as an internal port.

Please show us what you have tried, and what happened.


(Pankajkgoel) #5

I want to connect to an external service which is not dockerized.
9500 cannot be part of a binding. Since there is something running on that port on HOST. Trying to provide a mapping would give Bind Address is already in use and docker is not initialized.

The binding is mentioned only for the services which are accessed via HOST. Here are I am trying to access a service on HOST


(Mrdelorenzi) #6

You will have to show your dockerfile, and compose file.