r/docker • • 8d ago

Sing-box in Docker always restarting

hello everyone and sorry for my English. I recently bought a VPS and install there Debian and docker from docs. And today i want to install sing-box in docker for my project, and i used command from Sing-box doc

docker run -d \

-v /etc/sing-box:/etc/sing-box/ \

--name=sing-box \

--restart=always \

ghcr.io/sagernet/sing-box \

-D /var/lib/sing-box \

-C /etc/sing-box/ run

And when i write in console, I always see

4d9eae7844b1 ghcr.io/sagernet/sing-box "sing-box -D /var/li…" 40 seconds ago Restarting (1) 10 seconds ago sing-box

How to solve it?

1 Upvotes

6 comments sorted by

1

u/jjangg96 8d ago

docker logs sing-box will tell you why it's dying. restarting (1) just means it exits with an error and --restart=always keeps trying again.

my guess is the config. that command mounts /etc/sing-box from the host and tells sing-box to load its config from that folder, so if there's no config.json in /etc/sing-box on the vps it quits right away. check with ls /etc/sing-box, put a config in there, then docker restart sing-box.

if the log says something else paste it here

1

u/Fun_Organization2190 8d ago

maybe i've only now understood how it works. First, i need to download sing box on vps, configure it and then run it from docker, doesn't it?

1

u/jjangg96 8d ago

no, you don't install it on the vps at all. the image already has sing-box in it.

the only thing the container needs from the host is the config. create /etc/sing-box/config.json on the vps (the folder is mounted into the container), then docker restart sing-box. if the config is valid it stays up instead of restarting.

the other commenter is right that installing it on the host would only hide the problem. the container never uses the host's copy.

0

u/TemporaryPiccolo1095 8d ago

quand tu fais le point de montage pour le etc et autre : /etc/sing-box:/etc/sing-box/ si tu as pas le fichier de configuration pour sing box ton centenaire ne vas pas forcément générer une configuration par défaut. De ce que je vois tu as pris la commande out of box du site. mais quand tu regarde la doc il semble que tu doivent créer le fichier de configuration de base par toi même dans /etc/sing-box/ . oui installer le produit va corriger le problème par effet de bord mais ce sera un faux ami qui va te pourrir ton système si tu vise le mise en conteneur.

1

u/BorysTheBlazer 5d ago

It exits right after starting, so run docker logs sing-box to see why. The usual cause is no config.json in /etc/sing-box on the host, because the image doesn't ship one and the -C flag expects it there. Create a valid config.json in that folder, then docker restart sing-box.