Overview
Running Clash as a service keeps the core active in the background, independent of a GUI window. This is useful for routers, servers and shared machines.
Service model
A service should have a clear configuration path, log path, restart policy and permission model. On desktops, make sure it does not conflict with a GUI client running its own core.
Operational checklist
- Confirm the service user can read the profile and provider cache.
- Use stable ports that do not conflict with other software.
- Keep logs rotated and readable.
- Document how to stop or reload the service safely.
Support Checks
If the service starts but clients needs connection settings confirmed, check firewall rules, bind addresses and whether the profile was loaded from the expected location.
Related pages
Reference examples
These examples mirror the corresponding Chinese documentation page so the English page carries the same configuration material.
cp clash /usr/local/bin
cp config.yaml /etc/clash/
cp Country.mmdb /etc/clash/[Unit]
# reference note
After=network-online.target
[Service]
Type=simple
Restart=always
ExecStart=/usr/local/bin/clash -d /etc/clash
[Install]
WantedBy=multi-user.targetsystemctl daemon-reloadsystemctl enable clashsystemctl start clashsystemctl status clash
journalctl -xeservices:
clash:
image: ghcr.io/dreamacro/clash
restart: always
volumes:
- ./config.yaml:/root/.config/clash/config.yaml:ro
# reference note
ports:
- "7890:7890"
- "7891:7891"
# reference note
network_mode: "bridge"services:
clash:
image: ghcr.io/dreamacro/clash-premium
restart: always
volumes:
- ./config.yaml:/root/.config/clash/config.yaml:ro
# reference note
ports:
- "7890:7890"
- "7891:7891"
# reference note
cap_add:
- NET_ADMIN
devices:
- /dev/net/tun
network_mode: "host"docker-compose up -ddocker-compose logsdocker-compose stop