在打包GPTCache的docker镜像的时候踩到的一个坑
Dockerfile如下:
FROM ubuntu:20.04
RUN apt-get update && \
apt-get install -y \
zip \
curl \
wget \
unzip \
python3.8 \
python3-pip \
libgl1-mesa-glx
RUN pip3 install -U pip
RUN pip3 install gptcache
WORKDIR /workspace
CMD ["gptcache_server"]
当我通过以上dockerfile创建的image创建容器并启动服务时:
$ docker run -p 4000:4000 gptcache:v0
出现报错:
curl: (56) recv failure: 连接被对方重设
看了下容器内部端口状态:
$ netstst -tunlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 127.0.0.1:4000 0.0.0.0:* LISTEN 1/python3
只监听了127.0.0.1
, 需要在起server的时候指定host为0.0.0.0
来监听所有地址的4000端口, 更新docker file:
FROM ubuntu:20.04
RUN apt-get update && \
apt-get install -y \
zip \
curl \
wget \
unzip \
python3.8 \
python3-pip \
libgl1-mesa-glx
RUN pip3 install -U pip
RUN pip3 install gptcache
WORKDIR /workspace
CMD ["gptcache_server", "-s", "0.0.0.0"]
此时:
$ netstst -tunlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:4000 0.0.0.0:* LISTEN 1/python3
再次创建容器运行:
$ docker run -p 8000:8000 gptcache:v0
如果要用其他端口可以用指令覆盖dockerfile里的CMD:
$ docker run -p 4000:4000 -it gptcache:v0 gptcache_server -s 0.0.0.0 -p 4000