openclaw / Dockerfile
a8926764's picture
Update Dockerfile
8e04e45 verified
FROM node:22-slim
# Install system dependencies
RUN apt-get update && apt-get install -y git && rm -rf /var/lib/apt/lists/*
# Install OpenClaw globally
RUN npm install -g openclaw@latest
# Create config directory
RUN mkdir -p /root/.openclaw
# Set up environment for Hugging Face Spaces
ENV PORT=18789
ENV OPENCLAW_GATEWAY_MODE=local
ENV OPENCLAW_GATEWAY_PASSWORD=${OPENCLAW_GATEWAY_PASSWORD}
# Expose the port (Hugging Face default)
EXPOSE 18789
# Create a startup script that generates config and starts OpenClaw
RUN echo '#!/bin/bash\n\
set -x\n\
\n\
# Check for required gateway password\n\
if [ -z "$OPENCLAW_GATEWAY_PASSWORD" ]; then\n\
echo "WARNING: OPENCLAW_GATEWAY_PASSWORD is not set. Using default password '\''openclaw'\''."\n\
export OPENCLAW_GATEWAY_PASSWORD=openclaw\n\
else\n\
echo "Gateway password is set via environment variable"\n\
fi\n\
\n\
# Create critical missing directories\n\
mkdir -p /root/.openclaw/agents/main/agent\n\
mkdir -p /root/.openclaw/agents/main/sessions\n\
mkdir -p /root/.openclaw/credentials\n\
\n\
# Generate minimal config if not exists\n\
if [ ! -f /root/.openclaw/openclaw.json ]; then\n\
cat > /root/.openclaw/openclaw.json << EOF\n\
{\n\
"gateway": {\n\
"mode": "local",\n\
"bind": "lan",\n\
"port": 18789,\n\
"trustedProxies": ["0.0.0.0/0"],\n\
"auth": {\n\
"mode": "token",\n\
"token": "${OPENCLAW_GATEWAY_PASSWORD}"\n\
},\n\
"controlUi": {\n\
"allowInsecureAuth": true\n\
}\n\
}\n\
}\n\
EOF\n\
fi\n\
\n\
# Fix permissions\n\
chmod 700 /root/.openclaw\n\
if [ -f /root/.openclaw/openclaw.json ]; then\n\
chmod 600 /root/.openclaw/openclaw.json\n\
fi\n\
\n\
# Start OpenClaw gateway\n\
echo "Starting OpenClaw gateway on port 18789..."\n\
echo "Gateway access password: $OPENCLAW_GATEWAY_PASSWORD"\n\
exec openclaw gateway run --port 18789 --allow-unconfigured\n\
' > /usr/local/bin/start-openclaw && chmod +x /usr/local/bin/start-openclaw
CMD ["/usr/local/bin/start-openclaw"]