Skip to content

Running in Docker

From version 2.31.0 WireMock has an official Docker image.

Start a single WireWock container with default configuration

Section titled “Start a single WireWock container with default configuration”
Terminal window
docker run -it --rm \
-p 8080:8080 \
--name wiremock \
wiremock/wiremock:3.13.1

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

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.:

Terminal window
docker run -it --rm \
-p 8443:8443 \
--name wiremock \
wiremock/wiremock:3.13.1 \
--https-port 8443 --verbose

Passing command line arguments as environment variable

Section titled “Passing command line arguments as environment variable”

Starting from 3.2.0-2, the Docker image supports passing command line arguments standalone version as the environment variable. Environment variable WIREMOCK_OPTIONS can be passed to container consisting of all command line arguments e.g.:

Terminal window
docker run -it --rm \
-e WIREMOCK_OPTIONS='--https-port 8443 --verbose' \
-p 8443:8443 \
--name wiremock \
wiremock/wiremock:3.13.1

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.:

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

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-3.13.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:

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

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"]

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"]

You can also mount your local __files and mappings files into the container e.g:

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