Examples:
describe 'My Dockerfile' do
describe docker_build('.') do
it { should have_maintainer /John Doe/ }
it { should have_cmd ['/bin/dash'] }
it { should have_expose '80' }
end
end
describe docker_build(path: '.') do
it { should have_maintainer 'John Doe "[email protected]"' }
it { should have_maintainer(/John Doe/) }
it { should have_cmd %w(2 2000) }
it { should have_label 'description' }
it { should have_label 'description' => 'My Container' }
it { should have_expose '80' }
it { should have_expose(/80$/) }
it { should have_env 'container' }
it { should have_env 'container' => 'docker' }
it { should have_env 'CRACKER' => 'RANDOM;PATH=/tmp/bin:/sbin:/bin' }
it { should have_entrypoint ['sleep'] }
it { should have_volume '/volume1' }
it { should have_volume %r{/vol.*2} }
it { should have_user 'nobody' }
it { should have_workdir '/opt' }
it { should have_workdir %r{^/op} }
it { should have_onbuild 'RUN echo onbuild' }
it { should have_stopsignal 'SIGTERM' }
end
Checking the Attribute Values Using the its
Method
describe docker_build(path: '.') do
its(:maintainer) { should eq 'John Doe "[email protected]"' }
its(:cmd) { should eq %w(2 2000) }
its(:labels) { should include 'description' }
its(:labels) { should include 'description' => 'My Container' }
its(:exposes) { should include '80' }
its(:env) { should include 'container' }
its(:env) { should include 'container' => 'docker' }
its(:entrypoint) { should eq ['sleep'] }
its(:volumes) { should include '/volume1' }
its(:user) { should eq 'nobody' }
its(:workdir) { should eq '/opt' }
its(:onbuilds) { should include 'RUN echo onbuild' }
its(:stopsignal) { should eq 'SIGTERM' }
end
describe docker_build(path: '.') do
its(:size) { should be < 20 * 2**20 } its(:arch) { should eq 'amd64' }
its(:os) { should eq 'linux' }
end
describe docker_build(path: '../dockerfiles/Dockerfile-nginx') do
end
describe docker_build(template: 'Dockerfile1.erb') do
end
Building from a Template with a Context
describe docker_build(
template: 'Dockerfile1.erb', context: {version: '8'}
) do
it { should have_maintainer(/John Doe/) }
it { should have_cmd %w(/bin/sh) }
end
describe docker_build(string: "FROM nginx:1.9\n [...]") do
end
Building from a Docker Image ID
describe docker_build(id: '07d362aea98d') do
end
Building from a Docker Image Name
describe docker_build(id: 'nginx:1.9') do
end