在Travis-ci上的Docker容器

我有一个Dockerfile,我试图使用RSpec,serverspec和docker-api进行testing。 在本地(使用boot2docker,因为我在OS X上)这个工程很好,所有我的testing通过,但在travis-ci没有testing通过。 我的.travis.yml文件是这样的:

 language: ruby rvm: - "2.2.0" sudo: required cache: bundler services: - docker before_install: - docker build -t tomasbasham/nginx . - docker run -d -p 80:80 -p 443:443 --name nginx -v $(pwd)/nginx.conf:/etc/nginx/nginx.conf tomasbasham/nginx script: bundle exec rspec 

我在这里做了一些明显的错误吗? 我已经创build并在travis-ci上运行的存储库位于GitHub上 。 可能还有一些我不知道的错误

TL;博士

一个容器必须在前台运行它的程序。


你的Dockerfile是这个问题。 从你提供的github仓库中 ,Dockerfile的内容是:

 # Dockerfile for nginx with configurable persistent volumes # Select nginx as the base image FROM nginx MAINTAINER Tomas Basham <me@tomasbasham.co.uk> # Install net-tools RUN apt-get update -q && \ apt-get install -qy net-tools && \ apt-get clean # Mount configurable persistent volumes VOLUME ["/etc/nginx/sites-enabled", "/etc/nginx/certs", "/etc/nginx/conf.d", "/var/log/nginx", "/var/www/html"] # Expose both HTTP and HTTPS ports EXPOSE 80 443 # ENTRYPOINT ENTRYPOINT ["service", "nginx", "start"] 

在debuggingRSpec / serverspectesting之前,您应该确保docker映像能够运行一个容器。

Dockerfile所在的目录中键入这些命令:

 docker build -t tmp . docker run --rm -it tmp 

如果你把你的shell提示给你,这意味着你的容器停止运行。 如果你的容器没有启动,那么你的testing套件将会失败。


dockerfile有什么问题

您定义ENTRYPOINT ["service", "nginx", "start"]的入口点将执行一个命令,这个命令将在后台启动nginx程序。 这意味着最初由docker( /bin/service )运行的进程将终止,docker将检测到并停止你的容器。

要在前台运行nginx,必须运行nginx -g daemon off; 你可以在Dockerfile中find官方的nginx镜像 。 但是既然你把daemon off; 在你的nginx.conf文件中,你只需要用nginx

我build议你从Dockerfile中删除入口点(并从nginxconfiguration中删除daemon off; ,它应该可以正常工作。


serverspec

一旦你得到一个运行的容器,你将不得不把重点放在我没有经验的serverspec部分。