gohar shah
gohar shah

Reputation: 175

Issue in exposing docker containers

I have the following code sending client to the server and retrieving the result from the server. I have a firewall machine and my machine (server) is behind a firewall - I am connecting to the port 22 (ssh) on server machine on port 22238 on a firewall machine. I have redirected port 5555 on firewall machine to port 5555 on the machine (server). My issue is I am unable to send the data from the client to the server using socket interface.

I am running a client and server in a docker container

server docker container

 docker run --rm -it -p 192.168.xx.xx8:5555:5555 server bash

client docker container

 docker run --rm -it -p 192.168.xx.xx0:5555:5555 client bash

context=zmq.Context()
socket=context.socket(zmq.REP)
socket.bind("tcp://0.0.0.0:5555")
while True:
 message=socket.recv_pyobj()
 print("%s:%s" %(message.get(1)[0],message.get(1)[1]))
 socket.send_pyobj({1:[message.get(1)[0],message.get(1)[1]]})

server.py

context=zmq.Context()
print("Connecting")
socket=context.socket(zmq.REQ)
socket.connect("tcp://192.168.xx.xx8:5555")
name="Max"
while True:
  message=input("Message: ")
  socket.send_pyobj({1:[name,message]})
  message2=socket.recv_pyobj()
  print("%s:%s" %(message2.get (1)[0], message2.get(1)[1]))

Thanks help is highly appreciated.

Upvotes: 0

Views: 88

Answers (1)

SamR
SamR

Reputation: 336

I don't see anything obviously wrong with the "client" and "server" scripts. Does the message interchange work if you simply run them in separate shells (not in containers)?

Does your dockerfile define ENTRYPOINT? If it only defines CMD, I think you have replaced CMD with bash and only get the bash process in the container, not your client/server executables.

Upvotes: 1

Related Questions