#19644: feat(docker): add init script support via /openclaw-init.d/
scripts
docker
size: XS
trusted-contributor
Cluster:
Docker and Deployment Improvements
## Summary
- Adds a Docker ENTRYPOINT that runs user scripts from `/openclaw-init.d/` before starting the gateway
- Standard Docker pattern (nginx, postgres, etc.) for customizing container startup
- No change to default behavior when no init scripts are mounted
## Fix from #18450
The previous PR (#18450) was reverted because init script exit codes were silently swallowed by the `sed` pipe (POSIX `sh` has no `pipefail`).
This version captures the exit code **before** piping output to `sed`:
```sh
output=$("$script" 2>&1)
rc=$?
printf '%s\n' "$output" | sed 's/^/ /'
if [ $rc -ne 0 ]; then
echo "[openclaw-init] WARNING: $(basename "$script") exited with status $rc"
fi
```
This properly detects and logs init script failures while still indenting output.
## Test plan
- [ ] No init scripts mounted → gateway starts normally (no output from entrypoint)
- [ ] Mount a dir with executable scripts → scripts run in order before gateway
- [ ] Non-executable files → skipped with warning message
- [ ] Init script fails → exit code detected and warning logged
- [ ] `docker run openclaw echo hello` → init scripts run, then echo (exec passthrough works)
🤖 Generated with [Claude Code](https://claude.com/claude-code)
<!-- greptile_comment -->
<h3>Greptile Summary</h3>
Re-introduces Docker init script support (`/openclaw-init.d/`) that was reverted from PR #18450. The fix correctly captures init script exit codes before piping output to `sed`, resolving the original POSIX `pipefail` issue. The entrypoint follows the standard Docker pattern of running user-mounted scripts before `exec`-ing the main CMD.
- The exit code capture fix (`output=$("$script" 2>&1); rc=$?`) properly addresses the reason for the revert — exit codes are no longer swallowed by the sed pipe
- Init script failures are **non-fatal** (only a WARNING is logged), which diverges from the postgres/nginx patterns cited in the PR description where init failures typically abort startup via `set -e`
- The `docker-compose.yml` CLI service overrides `entrypoint` entirely, so init scripts only apply to the gateway service — this is consistent with intended behavior
- The `ENTRYPOINT` uses a relative path (`scripts/docker-entrypoint.sh`) which works because `WORKDIR /app` is set, though the original PR used an absolute path (`/app/scripts/docker-entrypoint.sh`)
<h3>Confidence Score: 3/5</h3>
- This PR is generally safe to merge but has a design decision around non-fatal init script failures that should be intentionally confirmed
- The core exit-code-capture fix is correct and addresses the revert reason. The script is well-structured POSIX shell. However, the non-fatal handling of init script failures diverges from the cited postgres/nginx patterns (which use set -e and abort on failure), meaning users could have init scripts silently fail while the gateway starts in a potentially broken state. This is a design choice that should be explicitly confirmed rather than a bug.
- Pay close attention to `scripts/docker-entrypoint.sh` — the non-fatal error handling on lines 26-28 is the key design decision to evaluate
<sub>Last reviewed commit: fce976c</sub>
<!-- greptile_other_comments_section -->
<!-- /greptile_comment -->
Most Similar PRs
#9190: feat(docker): Add autonomous container self-restart and runtime pac...
by alexdredmon · 2026-02-05
81.4%
#6638: fix: make Dockerfile work on container platforms (Render, Railway, ...
by kaizen403 · 2026-02-01
81.1%
#6698: feat: Add CLI wrapper for Docker integration and update documentation
by barshopen · 2026-02-01
80.9%
#9999: Docker: fix token mismatch and add dev setup workflow
by benclarkeio · 2026-02-06
80.3%
#12504: fix: allow docker cli container to connect to gateway
by bvanderdrift · 2026-02-09
78.4%
#7133: feat: Automated Docker setup with environment-based configuration
by synetalsolutions · 2026-02-02
77.7%
#19229: feat: add Apple Container setup with Docker/Podman fallbacks
by navingate · 2026-02-17
76.7%
#8478: Security: remove --allow-unconfigured from default Dockerfile CMD
by uttej-badwane · 2026-02-04
76.5%
#17506: Fix Entrypoint in docker-compose
by NeilSCGH · 2026-02-15
75.6%
#23313: feat(docker): add optional build-arg OPENCLAW_INSTALL_DOCKER_CLI to...
by zhuxuwei88-bot · 2026-02-22
75.1%