0

I have created this Dockerfile and copied it into /my/project/wiremock directory, based on the samples from https://github.com/rodolpheche/wiremock-docker:

    FROM openjdk:8-jre-alpine

    ENV WIREMOCK_VERSION 2.27.1

    RUN apk add --update openssl

    # fix "No Server ALPNProcessors" when using https
    RUN apk add --update libc6-compat
    RUN ln -s /lib/libc.musl-x86_64.so.1 /lib/ld-linux-x86-64.so.2

    # grab su-exec for easy step-down from root
    # and bash
    RUN apk add --no-cache 'su-exec>=0.2' bash

    # grab wiremock standalone jar
    RUN mkdir -p /var/wiremock/lib/ \
      && wget https://repo1.maven.org/maven2/com/github/tomakehurst/wiremock-jre8- 
    standalone/$WIREMOCK_VERSION/wiremock-jre8-standalone-$WIREMOCK_VERSION.jar \
    -O /var/wiremock/lib/wiremock-jre8-standalone.jar

    WORKDIR /home/wiremock

    EXPOSE 7070 7443

    CMD java $JAVA_OPTS -cp /var/wiremock/lib/*:/var/wiremock/extensions/* 
    com.github.tomakehurst.wiremock.standalone.WireMockServerRunner

Then I created the following docker-compose.yml file inside /my/project/ directory

    version: '3'

    services:
      wiremock:
        image: rodolpheche/wiremock:latest
        container_name: miplata-wiremock-local
        build: ./wiremock/.
        ports:
          - "7070:8080"
          - "7443:8443"
        volumes:
          - ./wiremock/stubs:/home/wiremock

Children directories inside /my/project/wiremock/stubs are mappings and __files.

When I execute docker-compose up, the docker container works and I can make some requests that work fine. But my issue is, that changes inside the stubs directory are not refreshed automatically and then I need to restart the container every time that I create a new wiremock stub or update an existing one.

Do you have any idea if I am doing something wrong? It would be nice to continue working without restarting the container.

Thanks!!!!

Ara Kokeba
  • 149
  • 1
  • 4
  • 15

3 Answers3

5

My recommedation is to store both mappings and response bodies in files.

By default:

  1. Mapping files should be included in mappings folder
  2. Body files should be included in __files folder.

As per my knowledge the wiremock standalone java process does the followings (regardless if it runs on the host or in a container):

  1. automatically loads the latest changes in the response bodies files (from __files folder)
  2. requires a POST call to __admin/mappings/reset in order to reload the mappings. For the example in the question description the cURL command looks like curl -X POST http://localhost:7070/__admin/mappings/reset

Please see below both the mapping and the reponse body files:

  • mappings/hello.json
{
  "request": {
    "method": "GET",
    "url": "/hello"
  },
  "response": {
    "status": 200,
    "bodyFileName": "hello.json"
  }
}

  • __files/hello.json
{
  "message": "Hello World !"
}

For me all this works like a charm. Wiremock is an amazing pieace of software very useful for testing endpoints with stubs for different use cases.

jtonic
  • 609
  • 1
  • 7
  • 10
1

Changes to the contents of the stubs directory are not real-time refreshed in the WireMock application. It is possible to use the Swagger UI: http://localhost:8080/__admin/swagger-ui to reset it manually or the corresponding API call to automate it.

A. Kootstra
  • 6,827
  • 3
  • 20
  • 43
1

I think the path that contains the json files should be mapped to /home/wiremock/mappings inside docker instance.

    version: '3'

    services:
      wiremock:
        image: rodolpheche/wiremock:latest
        container_name: miplata-wiremock-local
        build: ./wiremock/.
        ports:
          - "7070:8080"
          - "7443:8443"
        volumes:
          - /path/to/json_files:/home/wiremock/mappings

If you are running as a docker instance then the command should look like this:

# json mapping files
# mappings-checkin-mode.json mappings-kiosk-mode.json
docker run -it --rm -v $PWD:/home/wiremock/mappings -p 5050:8080 --name wiremock wiremock/wiremock:2.32.0 --enable-stub-cors
Mesut GUNES
  • 7,089
  • 2
  • 32
  • 49
  • I have similar issue , I posted my question here https://stackoverflow.com/questions/70961765/docker-container-with-wiremock-could-not-find-stub-mappings – itgeek Feb 02 '22 at 19:40