1

python服务器代码:

#!/usr/bin/python           
import socket               
s = socket.socket()         
host = socket.gethostname() 
port = 12345                
s.bind((host, port))        
s.listen(5)                 
while True:
   c, addr = s.accept()
   print 'Got connection from', addr
   c.send('Thank you for connecting')
   c.close()

Python客户端代码

#!/usr/bin/python  
import socket               
s = socket.socket()         
host = socket.gethostname() 
port = 12345                
s.connect((host, port))
print s.recv(1024)
s.close    

Dockerfile:

FROM python:2-onbuild    
CMD ["python","./client.py"]

尽管他们正在成功构建映像,但出现了此错误 errno111。服务器开始运行,但客户端无法访问服务器。错误如下。我不知道是否必须向 dockerfile 添加任何其他数据,或者我是否应该对执行 docker 容器的方式做任何事情。Python 客户端和服务器在 Python IDLE 中完美执行。

Traceback (most recent call last):
   File "./client.py", line 9, in <module>
       s.connect((host,port))
   File "usr/local/lib/python2.7/socket.py", line 228, in meth
       return getattr(self._sock, name)(*args)
socket.error: [Errno 111] Connection refused
4

0 回答 0