Home > Enterprise >  How get syncthing docker container to autostart on reboot with correct settings
How get syncthing docker container to autostart on reboot with correct settings

Time:11-16

I'm quite new to docker.

I followed the instructions here to install and run syncthing in a docker container.

That worked great, but when I restarted the PC it auto-started the syncthing docker container, but without the extra settings in the .sh file (no volumes, no other settings I think) - it was like it was running the container with only the default settings - wouldn't sync with any other devices, nothing other than the default share, etc.

When I tried to run syncthing from the syncthing_run.sh script, it complained that there was already a docker container running with the name syncthing and I needed to delete or rename the container in order to run with that name.

I was able to get it running again with all the settings by doing sudo docker stop syncthing to stop the already-running container, then removing the --name line from the script:

IDu=$(id -u $(logname)) # Saves the logged in user id in the IDu variable
IDg=$(id -g $(logname)) # Saves the logged in user group in the IDg variable

docker run -d \
 --name syncthing \   # <------------- removed this line
 --hostname=syncthing-redacted \
 --network=host \
 -v $PWD/st-sync/:/var/syncthing/ \
 -v $PWD/data/:/var/syncthing/data/ \
 -v /redacted/:/var/syncthing/redacted/ \
 -e TZ="Australia/Sydney" \
 -e PUID=$IDu \
 -e PGID=$IDg \
 --restart=unless-stopped \
syncthing/syncthing:latest

then running sudo ~/docker/syncthing/syncthing_run.sh.

It seems to be running fine now, but I think it has created a new container? When I run sudo docker container ls -a | grep syncthing, I get:

88e447e1cd78   syncthing/syncthing:latest      "/bin/entrypoint.sh …"   27 minutes ago      Up 27 minutes (healthy)
7dd04d0701a7   syncthing/syncthing:latest      "/bin/entrypoint.sh …"   12 days ago         Exited (0) 34 minutes ago

How can I fix everything so the container will auto-run on startup, but with the correct settings from the .sh script, and the correct name of syncthing??

Also, how can I remove the duplicate container, and is it safe for me to do so without losing any data?

CodePudding user response:

I've discovered that docker run and docker start are different. docker run creates and then starts a new container.

What I should have done after the reboot is sudo docker start syncthing.

Running the script again created a new container. I had to stop the running container with sudo docker stop 88e447e1cd78 and then delete it with sudo docker rm 88e447e1cd78.

I think I could have just used sudo docker start syncthing after that point, but I also deleted the old container and then ran the script again to create a new container after reenabling the --name line.

  • Related