Q:

Docker containers on travis-ci

I have a Dockerfile that I am attempting to test using RSpec, serverspec and docker-api. Locally (using boot2docker as I am on OS X) this works great and all my test pass, but on travis-ci none of the tests pass. My .travis.yml file is as such:
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

Am I doing something noticeably wrong here? The repository I have created and is run on travis-ci is on GitHub. There may be something else amiss that I am unaware of

A:

tl;dr
A container MUST run its program in the foreground.

Your Dockerfile is the issue. From the github repository you provided, the Dockerfile content is:
# 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"]

Before debugging your RSpec/serverspec tests, you should make sure that docker image is able to run a container.
Type those commands from the directory which has the Dockerfile in:
docker build -t tmp .
docker run --rm -it tmp

If you get your shell prompt back to you, that means your container stopped running. If your container isn't starting, then your test suite will fail.

What's wrong with the dockerfile
The entrypoint you defined ENTRYPOINT ["service", "nginx", "start"] will execute a command that will, in turn, start the nginx program in the background. This means the process that was initially run by docker (/bin/service) will terminate, and docker will detect that and stop your container.
To run nginx in the foreground, one must run nginx -g daemon off; as you can find in the Dockerfile for the official nginx image. But since you put daemon off; in your nginx.conf file, you should be fine with just nginx.
I suggest you remove the entrypoint from your Dockerfile (and also remove the daemon off; from your nginx config) and it should work fine.

serverspec
Once you get a container which runs, you will have to focus on the serverspec part on which I'm not experienced with.

