Welcome to the final chapter of the OpenClaw tutorial!
In the previous chapter, we established the ProtocolSchema, the rulebook that ensures all our devices speak the same language.
We now have a complete system:
However, running this system right now is messy. You probably have three different terminal windows open. If you restart your computer, everything stops. If you want to move the system to a Raspberry Pi, you have to reinstall everything manually.
In this chapter, we will wrap everything into a neat package using Docker.
Imagine you want to ship a house to a new location. You wouldn't move the furniture piece by piece, then the bricks, then the pipes. You would want to put the whole house on a truck and drive it there.
Docker allows us to put our software into a "Container." This container includes the code, the settings, and the tools needed to run it. It guarantees that if it works on my computer, it will work on yours.
The Central Use Case: You want your Gateway and Control UI to run automatically on a home server 24/7. instead of typing commands every time the server reboots, you want a single command that says: "Start everything."
To understand Docker deployment, we need three simple concepts:
This is a text file that tells Docker how to build your application. It says things like: "Start with Node.js, copy my files, and run this command."
When you run the recipe (Dockerfile), you get an Image. This is a frozen snapshot of your application. You can share this image with friends.
We have two parts to run: the Gateway and the UI. Docker Compose is a tool that lets us run multiple containers at the same time using a single file (docker-compose.yml).
We will create a setup that launches both the backend and the frontend together.
Create a file named Dockerfile in the root folder of your project (where openclaw.mjs is).
# Start with a lightweight version of Node.js
FROM node:18-alpine
# Create a folder inside the container
WORKDIR /app
# Copy our project files into that folder
COPY . .
# Install dependencies
RUN npm install
# The command to start the brain
CMD ["node", "openclaw.mjs"]
Explanation:
FROM: We pick a base operating system that already has Node.js installed.COPY: We move our code from your computer into the container.CMD: This is the exact same command you typed in Chapter 1.
Now, we need to tell Docker to run this Gateway and the UI together. Create a file named docker-compose.yml in the root folder.
version: '3'
services:
# Service 1: The Brain
gateway:
build: .
ports:
- "8080:8080" # Map container port to your computer
# Service 2: The Dashboard
ui:
build: ./ui
ports:
- "5173:5173" # Map UI port to your computer
Explanation:
services: We list the parts of our app.build: Tells Docker where to find the Dockerfile for each part.ports: This opens a "window." It connects port 8080 inside the container to port 8080 on your real computer, so your iOS Node can connect.Now, open your terminal in the root folder and run one magic command.
docker-compose up
What happens:
http://localhost:5173. The Control UI loads!docker-compose up -d (detached), it runs in the background forever.How do these containers talk to each other and the outside world?
Docker creates a virtual network inside your computer.
Let's look closely at how the Configuration is handled. Remember Chapter 4: Configuration? We stored secrets in ~/.openclaw.
By default, Docker containers are isolated. They cannot see your home folder. We need to "mount" the configuration file so the container can read your API keys.
Updating docker-compose.yml for Configuration:
gateway:
build: .
ports:
- "8080:8080"
# Give the container access to your config file
volumes:
- ~/.openclaw:/root/.openclaw
Explanation:
volumes: This is a bridge.~/.openclaw) is the folder on your real computer./root/.openclaw) is where it appears inside the container.openclaw.mjs runs inside Docker, it finds the config file just as if it were running natively.In this final chapter, we learned how to professionalize our deployment.
Congratulations! You have completed the OpenClaw tutorial series.
You started with nothing and built:
You now have a fully functional, extensible, and private home automation system. From here, you can write new scripts in OpenProse, add new sensors, or build new nodes. The system is yours to command.
End of Tutorial.
Generated by Code IQ