【发布时间】:2019-12-08 08:57:48
【问题描述】:
我正在尝试构建 docker 映像以部署 Python 应用程序 RESTful API 的自动化测试。我正在使用 docker-compose 运行应用程序,它构建了几个容器(webserver、后端服务器、数据库、nginx 等)。有一个单独的 python/pytest 应用程序,它可以通过 nginx 容器连接到目标应用程序
在本地运行指向容器 url 的 pytest 时,一切都很好。
当从测试 repo dockerfile 构建的 docker 容器运行时,后端服务会听到并响应所有请求。 nginx 容器日志显示正确的调用和预期的响应代码。后端容器日志显示调用已收到并已响应。
pytest 容器失败并显示...python2.7/site-packages/future/utils/__init__.py:456: RestRequestException
我是 Docker 新手,还不知道如何回到引发错误的地方。
这里是环境信息(docker容器pytest运行):
root@17ad466cd12f:/code/app# pytest -vvvvv
============================= test session starts ==============================
platform linux2 -- Python 2.7.9, pytest-4.3.0, py-1.8.0, pluggy-0.12.0 -- /root/.pyenv/versions/2.7.9/bin/python2.7
cachedir: .pytest_cache
rootdir: /code/app, inifile: pytest.ini
plugins: pspec-0.0.3, tavern-0.26.4
两个基本问题: 1. 对如何进行的建议? 2. 其他人看到了吗?测试容器似乎无法听到来自应用程序端点的响应。
在尝试了一些事情(盲目地)之后,nginx 容器不再监听来自 pytest 容器的 http 调用。现在才得到
ConnectionError: HTTPSConnectionPool(host='api.dev.bdev.us', port=443): Max retries exceeded with url: /api/v2/profiles/ (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7fcddede8550>: Failed to establish a new connection: [Errno 111] Connection refused',))
这里是 Dockerfile:
FROM bepress/build-base-python:2.7.9
ENV API_TEST_SERVICE .dev.bdev.us
RUN apt-get update && apt-get install -y \
python-virtualenv \
python-argparse \
nano \
curl \
git
CMD bash
# Switch to Python 2.7.9 globally
RUN pyenv global 2.7.9
RUN pip install pip --upgrade
RUN pip install --upgrade --ignore-installed six setuptools
RUN pip install ndg-httpsclient pyasn1 pyOpenSSL
RUN mkdir /code
WORKDIR /code
ADD requirements.txt /code
RUN pip install --ignore-installed -r requirements.txt --cache-dir /pip-cache
WORKDIR /code/app
ADD . /code/app
EXPOSE 80
EXPOSE 443
运行命令:
docker run --name egs-api-tests -i python2 bash
尝试监听来自发布端口 80 和 443 的 nginx 容器对 http 请求的响应。
尝试 -p 443:443 或 -p 80:80 会抛出端口已在使用中的错误。
从容器 ping 到 google.com 工作,到 api.dev.bdev.us(到 nginx 服务容器的 url)
【问题讨论】:
-
你连代码都没有发给我们看看……
-
不确定要发布什么代码。有什么帮助?
-
已经发布了一些代码和输出。
-
已添加更多代码和详细信息以及所述问题的解决方案。仍在处理从测试容器直接连接到db容器中的数据库
标签: python-2.7 rest docker http port