Skip to content

Instantly share code, notes, and snippets.

@megadix
Last active February 23, 2023 08:18
Show Gist options
  • Select an option

  • Save megadix/98daa4b5fd52fdcb96312f92016e3490 to your computer and use it in GitHub Desktop.

Select an option

Save megadix/98daa4b5fd52fdcb96312f92016e3490 to your computer and use it in GitHub Desktop.
Start a Wiremock Docker container using Windows PowerShell
<#
.SYNOPSIS
Start a Wiremock Docker container
.DESCRIPTION
This script starts a Docker container using image rodolpheche/wiremock by Rodolphe Chaigneau:
https://hub.docker.com/r/rodolpheche/wiremock/
You can provide various options like HTTP and HTTPS ports, name of container, etc.
.PARAMETER http
HTTP port used by Wiremock and exposed by the container.
.PARAMETER https
HTTPS port used by Wiremock and exposed by the container.
.PARAMETER interactive
Should container run in interactive (i.e. console) mode or not. Default is False (= non-interactive).
.PARAMETER verbose
Turn on verbose logging. See
http://wiremock.org/docs/running-standalone/
for details
.PARAMETER persist
Do not delete container after shutdown, i.e. suppres "--rm" parameter of "docker run" command.
.PARAMETER name
Name of the container.
.EXAMPLE
Run a container named "wiremock" on port 8080 (http) and 8443 (https) in background, non-verbose, delete it when stopped.
Run-Wiremock.ps1
.EXAMPLE
Run a container named "custom-wiremock" on port 8082 (http) and 8445 (https) in foreground, verbose, persisted when stopped.
Run-Wiremock.ps1 8082 8445 -interactive -verbose -persist -name custom-wiremock
#>
param(
# HTTP port
[Int32]$http = 8080,
# HTTPS port
[Int32]$https = 8443,
# Run docker container interactively
[Switch]$interactive = $false,
# Wiremock verbose mode
[Switch]$verbose = $false,
# Do not remove container after shutdown
[Switch]$persist = $false,
[String]$name = "wiremock"
)
$commandline = "docker run"
If (-not $persist) {$commandline += " --rm"}
$(If (-not $interactive) {$commandline += " -d"})
$commandline += " --name $name"
$commandline += " -p " + $http + ":" + $http + " "
$commandline += " -p " + $https + ":" + $https + " "
$commandline += " wiremock/wiremock"
$commandline += " --port " + $http
$commandline += " --https-port " + $https
$(If ($verbose) {$commandline += " --verbose"})
$commandline += " --global-response-templating"
Invoke-Expression $commandline
@tomakehurst
Copy link

Hey, this is useful!

We've adopted Rodolphe's Docker image into the WireMock project now, so please can I suggest pointing this to the official image: https://hub.docker.com/r/wiremock/wiremock?

@megadix
Copy link
Author

megadix commented Feb 23, 2023

Thank you for the suggestion @tomakehurst , it worked perfectly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment