我在python flask_endpoint.py文件中发出一个HTTP请求,该请求请求一个URL,并且运行良好。
list_of_words = split_and_clean(question)
url = "http://azure1.com:5000" + \
"/model?q={0}".format(
'+'.join(list_of_words).replace('&', '%26')
)
resp = requests.get(url).json()
但是,当我使用docker容器调用相同的端点时,出现此错误。
ConnectionError: HTTPConnectionPool(host='azure1.com', port=5000): Max retries exceeded with url: /model?q=what+is+this (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7fe636384490>: Failed to establish a new connection: [Errno 110] Connection timed out',))
这是我使用的docker文件供参考
FROM ubuntu:16.04
MAINTAINER Vivek Kaul "vkaul11@gmail.com"
#Install Ubuntu pkgs
COPY apt.conf /etc/apt/apt.conf
COPY . /product_info
WORKDIR /product_info
RUN apt-get update && apt-get install -y --no-install-recommends \
ca-certificates \
vim \
git \
python \
python-pip \
curl \
wget \
lsof \
libmysqlclient-dev \
python-dev \
python-mysqldb \
build-essential \
&& \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
#PYTHON requirements
RUN python --version
RUN pip install pip --upgrade
RUN pip install --upgrade setuptools
RUN pip install -r requirements.txt
EXPOSE 5002
RUN ls -la /product_info/key_matching/data
WORKDIR /product_info/key_matching
ENTRYPOINT ["python"]
CMD [ "key_matching_endpoint.py" ]
然后使用
docker run -p 5002:5002 product_info