在Docker容器中运行py.test作为服务

我正在build立一个dockerisedselenium电网。 我可以通过附加的pytest容器(见下面)发送pythontesting[pytest运行]。 但是我已经安装了另一个要控制pytest的LAMP容器。 所以我想让pytest容器独立运行,运行空闲并等待来自LAMP容器的命令。

我有这个Dockerfile:

# Starting from base image FROM ubuntu #----------------------------------------------------- # Set the Github personal token ENV GH_TOKEN blablabla # Install Python & pip RUN apt-get update RUN apt-get upgrade -y RUN apt-get install -y python python-pip python-dev && pip install --upgrade pip # Install nano for #debugging RUN apt-get install -y nano # Install xvfb RUN apt-get install -y xvfb # Install GIT RUN apt-get update -y && apt-get install git -y # [in the / folder] RUN git clone https://$GH_TOKEN:x-oauth-basic@github.com/user/project.git /project # Install dependencies via pip WORKDIR /project RUN pip install -r dependencies.txt #----------------------------------------------------- # CMD ["/bin/bash"] 

我手动启动pytest容器[用于开发]:

 docker run -dit -v /project --name pytest repo/user:py 

事情是我完成了开发,我想从docker docker-compose启动pytest容器,并将其连接到其他容器(带有链接和容量)。 我只是不能让它熬夜。

我用这个:

 pytest: image: repo/user:py volumes: - "/project" command: "/bin/bash tail -f /dev/null" 

但没有工作。

那么,在Dockerfile中,我应该使用特定的CMD还是ENTRYPOINT?

我应该使用docker-compose文件中的一些command吗?

我不太确定你的testing是如何执行的,但是我想我也有类似的用例。 你可以看到我在cmd.sh的 Envoy项目中做了这个工作 ,还有一个示例testing 。

这是我如何运行我的testing。 我也在使用pytest,但这并不重要:1.使用docker-compose调出堆栈,不进行testing2.等待堆栈准备好请求。 对我来说,这意味着轮询200响应3.单独运行testing容器,但要确保它使用与组成堆栈相同的networking。

这可以通过几种方式来完成。 你可以把这一切都放在一个Bash脚本中,并通过你的主机来控制它。

在我的情况下,我从Python容器中完成这一切。 它有点绕了一圈,但主意是有一个主机启动的Pythontesting容器。 然后,容器本身使用组合来调出主机上的栈(dockerception)。 然后在testing容器中运行pytesttesting。 完成后,它将堆栈合并起来,并返回代码。