自动创builddocker容器并启动python脚本
我正在创build一个自动化的unit testing系统,它将利用dockertesting用Python编写的单个学生作业,并对单个unit testing文件进行testing。
我已经创build了一个网站,学生可以上传他们的任务,但我有点不确定如何让Docker工作的自动化。
工作stream程如下所示:
- 学生上传一个作业进行标记
- 这被复制到一个包含docker的linux主机
- 该文件在等待testing时坐在这里
所以,假设我有二十名学生在那里上传.py文件,这些文件被命名为他们独特的学生号码,我可以:
- 创build一个运行Ubuntu和Python的Docker容器
- 将学生文件和unit testing复制到此容器中
- 运行unit testing
- 将结果输出为文本文件
- 将此文本文件复制回我的networking服务器以显示结果
有人能指出我正确的方向来开始这种自动化吗? 我真的只是在Docker方面的一些帮助,而不是从我的web服务器的文件复制到Docker主机。
谢谢。
是的,有可能为此使用Docker。
Dockerfile
看起来像这样:
FROM ubuntu MAINTAINER xxx <user@example.org> # update ubuntu repository RUN DEBIAN_FRONTEND=noninteractive apt-get -y update # install ubuntu packages RUN DEBIAN_FRONTEND=noninteractive apt-get -y install python python-pip # install python requirements RUN pip install ... # define a mount point VOLUME /student.py # define command for this image CMD ["python","/student.py"]
现在,你必须用docker build -t student_test .
来构build这个镜像docker build -t student_test .
。
要启动脚本并获取输出,您可以使用:
docker run --volume /path/to/s12345.py:/student.py student_test > student_results_12345.txt`.
需要使用--volume
参数,将学生脚本挂载到定义的挂载点。 另外,您可以一次启动多个容器。
所有path都是相对于当前的工作目录。
检出以下项目
使用Heroku buildpack创build一个docker镜像。 疯狂,但一个整洁的想法,如果你得到它的工作。