Tutorial: How to test your docker image in half a second

docker run -p 8080:80 nginx
dgoss run -p 8080:80 nginx
INFO: Starting docker container
INFO: Container ID: 25d23a24
INFO: Running Tests
File: /var/log/nginx/error.log: exists: matches expectation: [true]
File: /var/log/nginx/error.log: linkedto: matches expectation: ["/dev/stderr"]
File: /var/log/nginx/error.log: filetype: matches expectation: ["symlink"]
File: /var/log/nginx/access.log: exists: matches expectation: [true]
File: /var/log/nginx/access.log: linkedto: matches expectation: ["/dev/stdout"]
File: /var/log/nginx/access.log: filetype: matches expectation: ["symlink"]
Process: nginx: running: matches expectation: [true]
Port: tcp:80: listening: matches expectation: [true]
Port: tcp:80: ip: matches expectation: [["0.0.0.0"]]
HTTP: http://localhost: status: matches expectation: [200]
HTTP: http://localhost: Body: matches expectation: [Welcome to nginx!]
Package: nginx: installed: matches expectation: [true]
Package: nginx: version: matches expectation: [["1.11.10-1~jessie"]]
Total Duration: 0.012s
Count: 13, Failed: 0, Skipped: 0
INFO: Deleting container

Prerequisites

Installing our test tool

curl -fsSL https://goss.rocks/install | sh

So.. What is Goss?

Writing our test

docker run -p 8080:80 nginx:1.11.10
dgoss edit -p 8080:80 nginx:1.11.10
INFO: Starting docker container
INFO: Container ID: 9468c0c3
INFO: Run goss add/autoadd to add resources
goss a file /var/log/nginx/access.log /var/log/nginx/error.log
goss a process nginx
goss a port 80
goss a package nginx
goss a http http://localhost
exit
file:
/var/log/nginx/access.log:
exists: true
mode: "0777"
size: 11
owner: root
group: root
linked-to: /dev/stdout
filetype: symlink
contains: []
/var/log/nginx/error.log:
exists: true
mode: "0777"
size: 11
owner: root
group: root
linked-to: /dev/stderr
filetype: symlink
contains: []
package:
nginx:
installed: true
versions:
- 1.11.10-1~jessie
port:
tcp:80:
listening: true
ip:
- 0.0.0.0
process:
nginx:
running: true
http:
http://localhost:
status: 200
allow-insecure: false
no-follow-redirects: false
timeout: 5000
body: []
dgoss run nginx

Modifying our tests by hand

file:
/var/log/nginx/access.log:
exists: true
linked-to: /dev/stdout
filetype: symlink
/var/log/nginx/error.log:
exists: true
linked-to: /dev/stderr
filetype: symlink
http:
http://localhost:
status: 200
timeout: 5000
body:
- Welcome to nginx!
file:
/var/log/nginx/access.log:
exists: true
linked-to: /dev/stdout
filetype: symlink
/var/log/nginx/error.log:
exists: true
linked-to: /dev/stderr
filetype: symlink
package:
nginx:
installed: true
versions:
- 1.11.10-1~jessie
port:
tcp:80:
listening: true
ip:
- 0.0.0.0
process:
nginx:
running: true
http:
http://localhost:
status: 200
timeout: 5000
body:
- Welcome to nginx!
dgoss run nginx

What’s next?

  • Goss — The tool used in this tutorial
  • dgoss — Helper tool packaged with goss, also used in this tutorial
  • dgoss-examples — Repo containing more complex examples of using dgoss to validate docker images
  • Goss manual — Goss documentation

Video version of this tutorial

--

--

--

CICD/Devops Consultant, author and maintainer of goss server testing tool. https://www.linkedin.com/in/elsabbahyahmed/

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Base64-encoded file uploads with Phoenix and Plug

Steps to Setup Firebase to your Flutter Application

Python for everyone

Golang: Using Regex Pattern Matching with net/http

Lisk Dev Update: Core 1.6.0 nears completion, extra security for Hub 1.12.0 and Lisk Mobile 1.0.0

Build Your Own Stock Market Data ETL Pipeline on AWS RDS

DAPR: future of cloud-native & microservices

Developing a Path Shortcuts Manager

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
aelsabbahy

aelsabbahy

CICD/Devops Consultant, author and maintainer of goss server testing tool. https://www.linkedin.com/in/elsabbahyahmed/

More from Medium

Everything about Monolithic Architecture

How to manually migrate Elasticsearch Index definitions between two different clusters

DockerCon2022 Key Takeaways: Docker And WebAssembly

What is Tekton?