- Newest
- Most votes
- Most comments
Hi,
Stream Manager binds to the localhost which is probably the reason why the client inside the container is not able to connect to the SM server.
I suggest you try connecting via the gateway of the network used by your container. If you are using the default network, this is most probably the network named bridge
.
You can list the available networks by running docker network ls
For instance my available networks are:
NETWORK ID NAME DRIVER SCOPE
9d81c010d50a bridge bridge local
d1fdeb535122 host host local
72f2a273972a none null local
Now you should find the network your container is running in.
To do that run docker inspect --format='{{json .NetworkSettings.Networks}}' <NAME_OF_THE_CONTAINER>
For me it is bridge
:
{"bridge":{"IPAMConfig":null,"Links":null,"Aliases":null,"NetworkID":"9d81c010d50a3e2b2d175e68bcdac6edb6c440677af479dc4256f612f6d4146c","EndpointID":"702afd9f1cab8d837baf9e0917a3a28fc7131e2b92acc8124500e2d05a178f58","Gateway":"240.10.0.1","IPAddress":"240.10.0.2","IPPrefixLen":24,"IPv6Gateway":"","GlobalIPv6Address":"","GlobalIPv6PrefixLen":0,"MacAddress":"02:42:f0:0a:00:02","DriverOpts":null}}
Ie, my container is running with bridge
network which is also the default. The gateway of the bridge network should be 172.17.0.1
by default, we can confirm that using docker network inspect bridge
Once you have the gateway address. You need to configure the Stream Manager client to talk over the gateway.
Modifying your example:
from stream_manager import StreamManagerClient
def main():
client = StreamManagerClient(host='172.17.0.1')
print(f"Connected to client: {client}")
if __name__ == "__main__":
main()
To learn more about docker networking: https://docs.docker.com/engine/tutorials/networkingcontainers/
You can also get the address outside the container by running HOST_GATEWAY_ADDRESS=$(ip addr show | grep "\binet\b.*\bdocker0\b" | awk '{print $2}' | cut -d '/' -f 1)
and then injected the variable into the container to use in code.
Thanks
Relevant content
- asked a year ago
- AWS OFFICIALUpdated 10 months ago
- AWS OFFICIALUpdated 10 months ago
- AWS OFFICIALUpdated 2 years ago
- AWS OFFICIALUpdated a year ago