Running in Docker

WARNING: This document is for an old WireMock 2.x baseline. See the documentation for the current WireMock 3.x baseline here

From version 2.31.0 WireMock has an official Docker image.

Getting started #

Start a single WireWock container with default configuration #

docker run -it --rm \
  -p 8080:8080 \
  --name wiremock \
  wiremock/wiremock:2.35.1

Access http://localhost:8080/__admin/mappings to display the mappings (empty set)

Start with command line arguments #

The Docker image supports exactly the same set of command line arguments as the standalone version. These can be passed to the container by appending them to the end of the command e.g.:

docker run -it --rm \
  -p 8443:8443 \
  --name wiremock \
  wiremock/wiremock:2.35.1 \
  --https-port 8443 --verbose

Mounting stub mapping files #

Inside the container, the WireMock uses /home/wiremock as the root from which it reads the mappings and __files directories. This means you can mount a directory containing these from your host machine into Docker and WireMock will load the stub mappings.

To mount the current directory use -v $PWD:/home/wiremock e.g.:

docker run -it --rm \
  -p 8080:8080 \
  --name wiremock \
  -v $PWD:/home/wiremock \
  wiremock/wiremock:2.35.1

Running with extensions #

WireMock extensions are packaged as JAR files. In order to use them they need to be made available at runtime and WireMock must be configured to enable them.

For example, to use the Webhooks extension we would first download wiremock-webhooks-extension-2.35.1.jar into the extensions directory under our working directory.

Then when starting Docker we would mount the extensions directory to /var/wiremock/extensions and enable the webhooks extension via a CLI parameter:

docker run -it --rm \
  -p 8080:8080 \
  --name wiremock \
  -v $PWD/extensions:/var/wiremock/extensions \
  wiremock/wiremock \
    --extensions org.wiremock.webhooks.Webhooks

Building your own image #

Inside the container, the WireMock uses /home/wiremock as the root from which it reads the mappings and __files directories. This means you can copy your configuration from your host machine into Docker and WireMock will load the stub mappings.

Wiremock utilizes a custom entrypoint script that passes all provided arguments as WireMock startup parameters. To modify the WireMock launch parameters it is recommended to override the entrypoint in your custom Docker image.

# Sample Dockerfile
FROM wiremock/wiremock:latest
COPY wiremock /home/wiremock
ENTRYPOINT ["/docker-entrypoint.sh", "--global-response-templating", "--disable-gzip", "--verbose"]

Docker Compose #

Configuration in compose file is similar to Dockerfile definition

# Sample compose file
version: "3"
services:
  wiremock:
    image: "wiremock/wiremock:latest"
    container_name: my_wiremock
    entrypoint: ["/docker-entrypoint.sh", "--global-response-templating", "--disable-gzip", "--verbose"]