How do you run a ZAP baseline scan with Docker?

BeginnerHands-onOWASP ZAP
Answer

Short answer

Run the official zaproxy/zap-stable image with zap-baseline.py -t <target URL>, mounting a folder to collect HTML/JSON/Markdown reports. The exit code tells you whether warnings or failures were found.

Command

mkdir -p zap-reports && chmod 777 zap-reports
docker run --rm -v $(pwd)/zap-reports:/zap/wrk:rw -t ghcr.io/zaproxy/zaproxy:stable \
  zap-baseline.py -t https://staging.shop.example.com \
  -r report.html -J report.json -w report.md

Useful options

Option Purpose
-t URL Target
-m 5 Spider for up to 5 minutes
-r / -J / -w / -x HTML / JSON / Markdown / XML report
-c zap.conf Rule config: set each rule to IGNORE, WARN or FAIL
-I Don't return failure on warnings
-a Include alpha passive rules

Exit codes

0 = no issues, 1 = at least one FAIL, 2 = at least one WARN (no FAIL), 3 = error.

Targeting a local container

Use the Docker network or host.docker.internal (Mac/Windows) / --network host (Linux) so ZAP can reach the app.

What to say in the interview

"docker run the ZAP stable image with zap-baseline.py against the staging URL, mounting /zap/wrk for HTML and JSON reports. A rules config file decides which findings warn or fail, and the exit code drives the pipeline."

All Security Tools questions Roadmap: OWASP ZAP — dynamic testing (DAST)

More on OWASP ZAP