Docs CLI Container (Docker)

Mockarty CLI in a container

Build a container from a released Mockarty CLI binary. Use the same CLI version on your workstation, in Docker and in CI.

Prepare the binary

Download mockarty-cli-linux-amd64 or mockarty-cli-linux-arm64 and checksums.txt from the same CLI release. Save them in a dedicated folder and open it in a terminal:

arch=amd64
asset="mockarty-cli-linux-$arch"
awk -v asset="$asset" '$2 == asset { print }' checksums.txt | sha256sum --check -

Save this as Dockerfile in the same folder:

FROM gcr.io/distroless/static-debian12:nonroot
ARG TARGETARCH
COPY --chmod=0755 mockarty-cli-linux-${TARGETARCH} /usr/local/bin/mockarty-cli
ENV HOME=/tmp
ENTRYPOINT ["/usr/local/bin/mockarty-cli"]
CMD ["mock", "serve"]
docker build --platform "linux/$arch" -t local/mockarty-cli:verified .
docker run --rm local/mockarty-cli:verified version

Use arch=arm64 for ARM64 Linux. Check the image tag and the version printed by mockarty-cli version before sharing the image. Keep the exact version tag or digest in your CI settings.

The image starts the stub server by default. To run another CLI command, pass it after the image name.

Stub server

mock serve starts an in-process HTTP server with the WireMock admin API and the
native Mockarty admin API. It loads WireMock, Mockoon and Mockarty stubs from
--data-dir and detects the format per file:

docker run --rm -p 8080:8080 \
  -v "$PWD/stubs:/data:ro" \
  local/mockarty-cli:verified mock serve \
  --data-dir /data

The server listens on 0.0.0.0:8080 by default.

WireMock admin API

Method Path Purpose
GET /__admin/health Liveness probe (200 + JSON)
GET /__admin/mappings List stubs
POST /__admin/mappings Create a stub (format auto-detected)
GET /__admin/mappings/{id} Fetch one stub
DELETE /__admin/mappings/{id} Remove a stub
POST /__admin/reset Remove every stub (destructive)
curl -X POST http://localhost:8080/__admin/mappings \
  -H 'Content-Type: application/json' \
  -d '{"request":{"method":"GET","url":"/api/users"},"response":{"status":200,"body":"{\"ok\":true}"}}'

curl http://localhost:8080/api/users
# {"ok":true}

Native Mockarty admin API

Available on the same port:

Method Path
POST / GET /__admin/api/v1/mocks
GET / DELETE /__admin/api/v1/mocks/{id}
GET / POST / DELETE /__admin/api/v1/stores/global

The native API is the one to use for chains, faker, JsonPath and stores — they
all work in standalone mode without an admin node.

Load runner

The script path is positional. The target URL lives inside the script; pass it
through a k6-compatible environment variable (__ENV.BASE_URL):

docker run --rm \
  -v "$PWD/scripts:/scripts:ro" \
  -v "$PWD/reports:/reports" \
  local/mockarty-cli:verified perf run \
  /scripts/load.js \
  --env BASE_URL=https://api.example.com \
  --vus 50 \
  --duration 5m \
  --out json:/reports/load.json

The container exits with 0 when the run met its thresholds; a breached
threshold, an abnormal stop or a run that measured nothing exits 99.

Test runner

test run runs a Mockarty-native manifest (the path is positional).
Ask for the JUnit report explicitly — a reporter without --reporter writes
nothing:

docker run --rm \
  -v "$PWD/tests:/tests:ro" \
  -v "$PWD/reports:/reports" \
  local/mockarty-cli:verified test run \
  /tests/manifest.yaml \
  --reporter junit --out junit:/reports/junit.xml

For a Postman collection, use postman run:

docker run --rm \
  -v "$PWD/collections:/collections:ro" \
  -v "$PWD/reports:/reports" \
  local/mockarty-cli:verified postman run /collections/api.json \
  --reporter junit --out junit:/reports/junit.xml

Fuzz runner

docker run --rm \
  -v "$PWD/api.yaml:/api.yaml:ro" \
  local/mockarty-cli:verified fuzz \
  --spec /api.yaml \
  --target https://api.example.com \
  --duration 60s

Chaos runner

Chaos experiments are executed by a connected admin server and change a live
Kubernetes cluster, so the container needs the server credentials and the
explicit acknowledgement:

docker run --rm \
  -e MOCKARTY_SERVER=https://mockarty.example.com \
  -e MOCKARTY_TOKEN=mk_xxx \
  -v "$PWD/experiments:/experiments:ro" \
  local/mockarty-cli:verified chaos run \
  --i-know-this-is-preview \
  -f /experiments/network-blip.yaml

You can also describe the experiment entirely with flags, for example
--type pod_kill --k8s-namespace app --selector app=web --duration 5m.

Isolated networks

Build and transfer the image using your organisation’s approved channel before running it without registry access. Mount tests and configuration as read-only. Give the container user, UID 65532, write access to report directories. When running with --read-only, add --tmpfs /tmp if the command needs a writable temporary directory.

Docker Compose

services:
  mocker:
    image: local/mockarty-cli:verified
    command: ["mock", "serve", "--data-dir", "/data"]
    volumes: ["./mocks:/data:ro"]
    ports: ["8080:8080"]

Testcontainers

Pass the image reference from your build with WithImage in Go or withImage in Java. See Testcontainers for Mockarty.

Where to next