2017-04-24 14:47:03 +00:00
|
|
|
---
|
|
|
|
title: About the docker_container Resource
|
2018-02-16 00:28:15 +00:00
|
|
|
platform: linux
|
2017-04-24 14:47:03 +00:00
|
|
|
---
|
|
|
|
|
|
|
|
# docker_container
|
|
|
|
|
2018-03-14 15:01:12 +00:00
|
|
|
Use the `docker_container` InSpec audit resource to test a Docker container.
|
2017-04-24 14:47:03 +00:00
|
|
|
|
2017-10-03 21:35:10 +00:00
|
|
|
<br>
|
|
|
|
|
2017-04-24 14:47:03 +00:00
|
|
|
## Syntax
|
|
|
|
|
|
|
|
A `docker_container` resource block declares the configuration data to be tested:
|
|
|
|
|
|
|
|
describe docker_container('container') do
|
|
|
|
it { should exist }
|
|
|
|
it { should be_running }
|
|
|
|
its('id') { should_not eq '' }
|
|
|
|
its('image') { should eq 'busybox:latest' }
|
|
|
|
its('repo') { should eq 'busybox' }
|
|
|
|
its('tag') { should eq 'latest' }
|
|
|
|
its('ports') { should eq [] }
|
|
|
|
its('command') { should eq 'nc -ll -p 1234 -e /bin/cat' }
|
|
|
|
end
|
|
|
|
|
2018-02-16 02:34:11 +00:00
|
|
|
<br>
|
|
|
|
|
2018-02-16 00:28:15 +00:00
|
|
|
## Resource Parameter Examples
|
2018-02-02 13:10:47 +00:00
|
|
|
|
2018-02-15 14:33:22 +00:00
|
|
|
### name
|
2018-02-02 13:10:47 +00:00
|
|
|
|
|
|
|
The container name can also be passed with the `name` resource parameter:
|
2017-04-24 14:47:03 +00:00
|
|
|
|
|
|
|
describe docker_container(name: 'an-echo-server') do
|
|
|
|
it { should exist }
|
|
|
|
it { should be_running }
|
|
|
|
end
|
|
|
|
|
2018-02-15 14:33:22 +00:00
|
|
|
### id
|
|
|
|
|
2017-04-24 14:47:03 +00:00
|
|
|
Alternatively, you can pass in the container id:
|
|
|
|
|
|
|
|
describe docker_container(id: '71b5df59442b') do
|
|
|
|
it { should exist }
|
|
|
|
it { should be_running }
|
|
|
|
end
|
|
|
|
|
2017-10-03 21:35:10 +00:00
|
|
|
<br>
|
|
|
|
|
2018-02-02 13:10:47 +00:00
|
|
|
## Property Examples
|
2017-10-03 21:35:10 +00:00
|
|
|
|
|
|
|
The following examples show how to use this InSpec resource.
|
|
|
|
|
2017-04-24 14:47:03 +00:00
|
|
|
### id
|
|
|
|
|
2018-02-02 13:10:47 +00:00
|
|
|
The `id` property tests the container id:
|
2017-04-24 14:47:03 +00:00
|
|
|
|
|
|
|
its('id') { should eq 'sha:71b5df59...442b' }
|
|
|
|
|
|
|
|
### repo
|
|
|
|
|
2018-02-02 13:10:47 +00:00
|
|
|
The `repo` property tests the value of the image repository:
|
2017-04-24 14:47:03 +00:00
|
|
|
|
|
|
|
its('repo') { should eq 'busybox' }
|
|
|
|
|
|
|
|
### tag
|
|
|
|
|
2018-02-02 13:10:47 +00:00
|
|
|
The `tag` property tests the value of the image tag:
|
2017-04-24 14:47:03 +00:00
|
|
|
|
|
|
|
its('tag') { should eq 'latest' }
|
|
|
|
|
|
|
|
### ports
|
|
|
|
|
2018-03-14 15:01:12 +00:00
|
|
|
The `ports` property tests the value the Docker ports:
|
2017-04-24 14:47:03 +00:00
|
|
|
|
|
|
|
its('ports') { should eq '0.0.0.0:1234->1234/tcp' }
|
|
|
|
|
|
|
|
### command
|
|
|
|
|
2018-02-02 13:10:47 +00:00
|
|
|
The `command` property tests the value of the container run command:
|
2017-04-24 14:47:03 +00:00
|
|
|
|
|
|
|
its('command') { should eq 'nc -ll -p 1234 -e /bin/cat' }
|
2018-02-02 13:10:47 +00:00
|
|
|
|
|
|
|
|
|
|
|
### Verify a running container:
|
|
|
|
|
|
|
|
describe docker_container('an-echo-server') do
|
|
|
|
it { should exist }
|
|
|
|
it { should be_running }
|
|
|
|
its('id') { should_not eq '' }
|
|
|
|
its('image') { should eq 'busybox:latest' }
|
|
|
|
its('repo') { should eq 'busybox' }
|
|
|
|
its('tag') { should eq 'latest' }
|
|
|
|
its('ports') { should eq [] }
|
|
|
|
its('command') { should eq 'nc -ll -p 1234 -e /bin/cat' }
|
|
|
|
end
|
|
|
|
|
|
|
|
<br>
|
|
|
|
|
|
|
|
## Matchers
|
|
|
|
|
2018-02-16 03:07:18 +00:00
|
|
|
For a full list of available matchers, please visit our [matchers page](https://www.inspec.io/docs/reference/matchers/).
|