#9190: feat(docker): Add autonomous container self-restart and runtime package installation
docs
app: web-ui
scripts
docker
stale
size: M
Cluster:
Docker and Deployment Improvements
## Summary
This PR significantly enhances the Docker deployment experience by enabling **autonomous container management** -
allowing the OpenClaw gateway to self-restart and install packages at runtime without manual intervention.
**Key Features:**
- ๐ **Container Self-Restart** - Gateway can restart itself via secure Docker socket proxy
- ๐ฆ **Runtime Package Installation** - Install npm/apt packages on-the-fly without rebuilding
- โก **Pre-baked Development Tools** - Common tools (gh, python3, ripgrep, jq) included in image
- ๐พ **Persistent Caches** - Volume mounts for npm/apt caches speed up subsequent installs
## Motivation
When running OpenClaw in Docker, users often need to:
1. Install additional tools for agent workflows (e.g., `gh` for GitHub operations)
2. Restart the gateway after configuration changes
3. Add npm packages for extended functionality
Previously, this required manual intervention: exec'ing into the container, rebuilding the image, or restarting
via `docker compose`. This PR enables the gateway to handle these operations autonomously, which is especially
valuable for:
- **Headless/remote deployments** (NAS, cloud VMs, Raspberry Pi)
- **Agent-driven workflows** that need to install tools on demand
- **Rapid iteration** without constant image rebuilds
## Docker Architecture
The setup introduces a **socket proxy sidecar** for secure Docker API access:
**Services:**
- `docker-socket-proxy` โ Exposes limited Docker API (restart only) on internal network
- `openclaw-gateway` โ Main gateway with elevated permissions, connects to proxy
- `openclaw-cli` โ Interactive CLI container
**Network flow:**
> Gateway โ Socket Proxy (:2375, internal only) โ Docker Daemon
The gateway never has direct access to the Docker socket.
## Security Model
Uses [tecnativa/docker-socket-proxy](https://github.com/Tecnativa/docker-socket-proxy) for **least-privilege
access**:
**Allowed:**
- `CONTAINERS=1` โ Container inspection
- `POST=1` โ Restart requests
**Denied (by default):**
- Container creation/deletion
- Image operations
- Network/volume manipulation
- All other Docker API endpoints
This is significantly safer than mounting `/var/run/docker.sock` directly into the gateway container.
## Files Changed
**Modified:**
- `Dockerfile` โ Pre-install common tools (gh, python3, ripgrep, jq, codex, clawhub)
- `docker-compose.yml` โ Add socket proxy service, volume caches, elevated permissions
- `docker-setup.sh` โ Add docker-home directory for persistent storage
- `.gitignore` โ Exclude Claude Code local settings
**Added:**
- `scripts/docker-restart.sh` โ Self-restart via socket proxy
- `scripts/docker-startup.sh` โ Runtime package installation entrypoint
- `scripts/open-dashboard.sh` โ Quick dashboard access with token
## New Helper Scripts
```bash
# Open the dashboard with authentication token
./scripts/open-dashboard.sh
# Start the Docker environment
./scripts/docker-startup.sh
# Restart the gateway container (called from within container)
./scripts/docker-restart.sh
```
## Trade-offs
**Container user: `node` โ `root`**
Running as root is required for `apt-get` and global `npm install`. The security trade-off is acceptable because:
- Container remains isolated from the host
- Socket access is proxied with minimal permissions
- Matches the common pattern for development/agent containers
**Attack surface**
Slightly larger than before, but mitigated by the socket proxy's allowlist approach.
## Test Plan
- [ ] Fresh `docker compose up` starts successfully
- [ ] Gateway can install packages at runtime (`npm install -g <package>`)
- [ ] Gateway can trigger self-restart via agent command
- [ ] Socket proxy blocks unauthorized Docker API calls
- [ ] `./scripts/open-dashboard.sh` opens browser with valid token
- [ ] Persistent volumes survive container restart
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
This PR updates the Docker image and compose setup to support running the gateway/CLI as `root`, adds a docker-socket-proxy sidecar intended to allow the gateway to self-restart via the Docker API, and adds helper scripts for restarting the container and opening the dashboard.
Key integration points are `Dockerfile` (baked-in apt/npm tooling + restart helper), `docker-compose.yml` (socket proxy, new volumes, root home layout), and `docker-setup.sh` (persisted docker-home + token/config syncing).
<h3>Confidence Score: 2/5</h3>
- This PR is not safe to merge as-is due to build-breaking Dockerfile references and inconsistent Docker home mounts.
- Score is reduced because `docker build` will fail (missing copied script), and the docker setup script can generate an extra compose file that mounts persistence paths under `/home/node` while the compose file uses `/root`, breaking the advertised persistence behavior. Additional issues reduce usability (non-portable dashboard opener, suppressed install logs).
- Dockerfile, docker-compose.yml, docker-setup.sh, scripts/open-dashboard.sh
<!-- greptile_other_comments_section -->
<sub>(3/5) Reply to the agent's comments like "Can you suggest a fix for this @greptileai?" or ask follow-up questions!</sub>
<!-- /greptile_comment -->
Most Similar PRs
#7133: feat: Automated Docker setup with environment-based configuration
by synetalsolutions ยท 2026-02-02
86.2%
#9999: Docker: fix token mismatch and add dev setup workflow
by benclarkeio ยท 2026-02-06
85.9%
#8050: fix: docker hardening
by christopherbarnett96 ยท 2026-02-03
84.4%
#12504: fix: allow docker cli container to connect to gateway
by bvanderdrift ยท 2026-02-09
84.3%
#6698: feat: Add CLI wrapper for Docker integration and update documentation
by barshopen ยท 2026-02-01
84.1%
#6638: fix: make Dockerfile work on container platforms (Render, Railway, ...
by kaizen403 ยท 2026-02-01
83.9%
#12629: Dockerfile: pre-install common CLI tools for agent runtime
by jhs129 ยท 2026-02-09
83.3%
#4695: Fixed the default CLI image to use published GHCR image
by TASMAYU ยท 2026-01-30
82.7%
#23313: feat(docker): add optional build-arg OPENCLAW_INSTALL_DOCKER_CLI to...
by zhuxuwei88-bot ยท 2026-02-22
82.1%
#11915: Docs: Docker + reverse proxy deployment notes and pairing pitfalls
by walshd1 ยท 2026-02-08
81.9%