2018-01-23 20:30:14 +00:00
|
|
|
---
|
|
|
|
title: About the docker_service Resource
|
2018-02-16 00:28:15 +00:00
|
|
|
platform: linux
|
2018-01-23 20:30:14 +00:00
|
|
|
---
|
|
|
|
|
|
|
|
# docker_service
|
|
|
|
|
2019-04-26 18:24:29 +00:00
|
|
|
Use the `docker_service` Chef InSpec audit resource to verify a docker swarm service.
|
2018-01-23 20:30:14 +00:00
|
|
|
|
|
|
|
<br>
|
|
|
|
|
2018-08-09 12:34:49 +00:00
|
|
|
## Availability
|
|
|
|
|
|
|
|
### Installation
|
|
|
|
|
2019-04-26 18:24:29 +00:00
|
|
|
This resource is distributed along with Chef InSpec itself. You can use it automatically.
|
2018-08-09 12:34:49 +00:00
|
|
|
|
|
|
|
### Version
|
|
|
|
|
|
|
|
This resource first became available in v1.51.0 of InSpec.
|
|
|
|
|
2018-01-23 20:30:14 +00:00
|
|
|
## Syntax
|
|
|
|
|
|
|
|
A `docker_service` resource block declares the service by name:
|
|
|
|
|
|
|
|
describe docker_service('foo') do
|
|
|
|
it { should exist }
|
|
|
|
its('id') { should eq '2ghswegspre1' }
|
|
|
|
its('repo') { should eq 'alpine' }
|
|
|
|
its('tag') { should eq 'latest' }
|
|
|
|
end
|
|
|
|
|
2018-02-02 13:13:56 +00:00
|
|
|
<br>
|
|
|
|
|
|
|
|
## Resource Parameter Examples
|
|
|
|
|
2018-01-23 20:30:14 +00:00
|
|
|
The resource allows you to pass in a service id:
|
|
|
|
|
|
|
|
describe docker_service(id: '2ghswegspre1') do
|
|
|
|
...
|
|
|
|
end
|
|
|
|
|
|
|
|
You can also pass in the fully-qualified image:
|
|
|
|
|
|
|
|
describe docker_service(image: 'localhost:5000/alpine:latest') do
|
|
|
|
...
|
|
|
|
end
|
|
|
|
|
|
|
|
<br>
|
|
|
|
|
2018-02-02 13:13:56 +00:00
|
|
|
## Property Examples
|
2018-01-23 20:30:14 +00:00
|
|
|
|
2019-04-26 18:24:29 +00:00
|
|
|
The following examples show how to use Chef InSpec `docker_service` resource.
|
2018-01-23 20:30:14 +00:00
|
|
|
|
|
|
|
### id
|
|
|
|
|
2018-02-02 13:13:56 +00:00
|
|
|
The `id` property returns the service id:
|
2018-01-23 20:30:14 +00:00
|
|
|
|
|
|
|
its('id') { should eq '2ghswegspre1' }
|
|
|
|
|
|
|
|
### image
|
|
|
|
|
2018-06-06 18:10:48 +00:00
|
|
|
The `image` property is a combination of `repository:tag` it tests the value of the image:
|
2018-01-23 20:30:14 +00:00
|
|
|
|
|
|
|
its('image') { should eq 'alpine:latest' }
|
|
|
|
|
|
|
|
### mode
|
|
|
|
|
2018-02-02 13:13:56 +00:00
|
|
|
The `mode` property tests the value of the service mode:
|
2018-01-23 20:30:14 +00:00
|
|
|
|
|
|
|
its('mode') { should eq 'replicated' }
|
|
|
|
|
|
|
|
### name
|
|
|
|
|
2018-02-02 13:13:56 +00:00
|
|
|
The `name` property tests the value of the service name:
|
2018-01-23 20:30:14 +00:00
|
|
|
|
|
|
|
its('name') { should eq 'foo' }
|
|
|
|
|
|
|
|
### ports
|
|
|
|
|
2018-02-02 13:13:56 +00:00
|
|
|
The `ports` property tests the value of the service's published ports:
|
2018-01-23 20:30:14 +00:00
|
|
|
|
|
|
|
its('ports') { should include '*:8000->8000/tcp' }
|
|
|
|
|
|
|
|
### repo
|
|
|
|
|
2018-02-02 13:13:56 +00:00
|
|
|
The `repo` property tests the value of the repository name:
|
2018-01-23 20:30:14 +00:00
|
|
|
|
|
|
|
its('repo') { should eq 'alpine' }
|
|
|
|
|
|
|
|
### replicas
|
|
|
|
|
2018-02-02 13:13:56 +00:00
|
|
|
The `replicas` property tests the value of the service's replica count:
|
2018-01-23 20:30:14 +00:00
|
|
|
|
|
|
|
its('replicas') { should eq '3/3' }
|
|
|
|
|
|
|
|
### tag
|
|
|
|
|
2018-02-02 13:13:56 +00:00
|
|
|
The `tag` property tests the value of image tag:
|
2018-01-23 20:30:14 +00:00
|
|
|
|
|
|
|
its('tag') { should eq 'latest' }
|
2018-02-02 13:13:56 +00:00
|
|
|
|
|
|
|
### Test a docker service
|
|
|
|
|
|
|
|
describe docker_service('foo') do
|
|
|
|
it { should exist }
|
|
|
|
its('id') { should eq '2ghswegspre1' }
|
|
|
|
its('repo') { should eq 'alpine' }
|
|
|
|
its('tag') { should eq 'latest' }
|
|
|
|
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/).
|
2018-02-02 13:13:56 +00:00
|
|
|
|
|
|
|
### exist
|
|
|
|
|
|
|
|
The `exist` matcher tests if the image is available on the node:
|
|
|
|
|
|
|
|
it { should exist }
|
|
|
|
|
|
|
|
|