Dockerize wiremock
Please, visit wiremock website for the official documentation.
Inspired by stackoverflow question.
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 /home/wiremock &&\
wget https://repo1.maven.org/maven2/com/github/tomakehurst/wiremock-jre8-standalone/$WIREMOCK_VERSION/wiremock-jre8-standalone-$WIREMOCK_VERSION.jar \
-O /home/wiremock/wiremock-jre8-standalone.jar
WORKDIR /home/wiremock
ENTRYPOINT ["java", "-jar", "wiremock-jre8-standalone.jar"]
Build
docker build . -t dehasi/wiremock
Run
docker run --rm -it \
-p 8080:7070 \
-v $(pwd)/mappings:/home/wiremock/mappings \
-v $(pwd)/files:/home/wiremock/__files \
dehasi/wiremock --port 7070 # we can add any params here
Example
All mappings should be in mappings
directory.
In example, there is hello.json
in mappings
{
"request": {
"method": "GET",
"url": "/hello"
},
"response": {
"status": 200,
"bodyFileName": "hello.json"
}
}
All mappings should be in files
directory.
There is hello.json
in files
directory.
{
"message": "Hello World !"
}
If we run the comand above, we’ll we that wiremock started on 7070 port.
/$$ /$$ /$$ /$$ /$$ /$$
| $$ /$ | $$|__/ | $$$ /$$$ | $$
| $$ /$$$| $$ /$$ /$$$$$$ /$$$$$$ | $$$$ /$$$$ /$$$$$$ /$$$$$$$| $$ /$$
| $$/$$ $$ $$| $$ /$$__ $$ /$$__ $$| $$ $$/$$ $$ /$$__ $$ /$$_____/| $$ /$$/
| $$$$_ $$$$| $$| $$ \__/| $$$$$$$$| $$ $$$| $$| $$ \ $$| $$ | $$$$$$/
| $$$/ \ $$$| $$| $$ | $$_____/| $$\ $ | $$| $$ | $$| $$ | $$_ $$
| $$/ \ $$| $$| $$ | $$$$$$$| $$ \/ | $$| $$$$$$/| $$$$$$$| $$ \ $$
|__/ \__/|__/|__/ \_______/|__/ |__/ \______/ \_______/|__/ \__/
port: 7070
enable-browser-proxying: false
disable-banner: false
no-request-journal: false
verbose: false
As we mapped 7070 to 8080, we have to use 8080
$ curl http://localhost:8080/hello
{
"message": "Hello World !"
}