How to reboot PC and have container start correctly?

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?

I suspect this means that it will not start on boot, since it was stopped on shutdown. I usually use --restart=always for things I want running.

Yes. The container was there, it just didn’t start at boot. The correct solution at this point would have been docker start syncthing to start the existing, named, but not running container.

Your data is (or should be, at least) safe in the volumes so you can remove and recreate the containers. What I would do:

  • Remove the old, not running container: docker rm 7dd04d0701a7
  • Stop and remove the new container that wasn’t named: docker kill 88e447e1cd78 && docker rm 88e447e1cd78
  • Edit your script to:
    • Include the --name again
    • Use --restart=always
  • Run that script to start a new container with the settings in question.

Then try a reboot and see what happens. If it starts, good. If it doesn’t, research what is required for docker containers to auto-start on your operating system.

Awesome, thanks so much for the quick reply. Yes I must have got confused with that error message and I thought it was already running.

I’ll try all those things now.

I have a question: why didn’t the 7dd04d0701a7 container remember the name that it was given originally, so I could type sudo docker start syncthing to start it? 88e447e1cd78 wasn’t specified with a name, so I understand that, by why not the original one? Why did I have to docker rm it and then recreate the container?

I’m pretty sure it did and you could have, but your script doesn’t do that, it attempts to create another container with the same name. There’s a big difference between docker run ... (creates a new container) and docker start ... (starts an existing one).

Aah, ok. Now I see the difference between docker run and docker start.

Thanks again!!

1 Like
version: "2.1"
services: 
 syncthing: 
  image: lscr.io/linuxserver/syncthing
  container_name: syncthing1
  hostname: syncthing
  environment: 
   - PUID=1000
   - PGID=1000
   - TZ=America/Chicago
   - UMASK=022
  volumes: 
   - /srv/docker/syncthing:/config
   - /data/share:/data1
  ports: 
   - 8384:8384
   - 22000:22000/tcp
   - 22000:22000/udp
   - 21027:21027/udp
  restart: unless-stopped

I prefer Docker Compose over standard Docker run commands. Docker compose does almost the same things as Docker run, but the config is stored in a YAML file, and you can spin up multiple containers in a single file. When it’s time to restart and/or update your docker compose stack, run the following command:

docker-compose up -d --force-recreate

There’s not really a need to use a bash script if the contents of your yaml file has your config in it. The “–force-recreate” option is not necessary on the first run, but it doesn’t hurt either, and it will work every other time you run it in the future. I have found that it’s generally safe to remove and/or recreate containers at will, as long as the config is mapped to a volume on the host.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.