Clash needs to run in the background. Because Golang does not currently provide a strong daemon implementation, we recommend using a third-party tool to create a Clash daemon.
systemd
Use the following commands to copy the Clash binary to /usr/local/bin and the configuration file to /etc/clash:
cp clash /usr/local/bin
cp config.yaml /etc/clash/
cp Country.mmdb /etc/clash/Create the systemd configuration file /etc/systemd/system/clash.service:
[Unit]
Description=Clash 守护进程, Go 语言实现的基于规则的代理.
After=network-online.target
[Service]
Type=simple
Restart=always
ExecStart=/usr/local/bin/clash -d /etc/clash
[Install]
WantedBy=multi-user.targetThen reload systemd with the following command:
systemctl daemon-reloadEnable Clash at system startup with the following command:
systemctl enable clashStart Clash immediately with the following command:
systemctl start clashCheck Clash status and logs with the following command:
systemctl status clash
journalctl -xeThis guide was contributed by ktechmidas (#754).
Docker
The project provides prebuilt Docker images for Clash and Clash Premium. On Linux, you can therefore deploy Clash with Docker Compose. However, you should be aware that running Clash Premium in a container is not recommended.
WARNING
Because Docker for Mac lacks host networking and TUN support, this setup will not work on macOS.
services:
clash:
image: ghcr.io/dreamacro/clash
restart: always
volumes:
- ./config.yaml:/root/.config/clash/config.yaml:ro
# - ./ui:/ui:ro # 仪表盘 Volume 映射
ports:
- "7890:7890"
- "7891:7891"
# - "8080:8080" # 外部控制 (RESTful API)
network_mode: "bridge"services:
clash:
image: ghcr.io/dreamacro/clash-premium
restart: always
volumes:
- ./config.yaml:/root/.config/clash/config.yaml:ro
# - ./ui:/ui:ro # 仪表盘 Volume 映射
ports:
- "7890:7890"
- "7891:7891"
# - "8080:8080" # 外部控制 (RESTful API)
cap_add:
- NET_ADMIN
devices:
- /dev/net/tun
network_mode: "host"Save this as docker-compose.yaml, and place your config.yaml in the same directory.
TIP
Before continuing, consult your platform's time-synchronization documentation. Some protocols may not work correctly when the clock is out of sync.
When ready, start Clash with the following command:
docker-compose up -dView the logs with the following command:
docker-compose logsStop Clash with:
docker-compose stop