Forgot to mount config externally in docker

When I created a docker container running Syncthing a few weeks ago, I forgot to to mount the config folder to a physical folder on the host. I only mounted the sync folders. I just realized that now when looking at my docker-compose.yml:

version: "2.1"
    image: syncthing/syncthing
    container_name: syncthing
    hostname: syncthing #optional
      - PUID=1000
      - PGID=1000
      - TZ=Europe/Copenhagen
      - /mnt/public/Backup/SyncThing/Data:/Data
      - /mnt/public/Backup/SyncThing/Www:/Www
      - 8384:8384
      - 22000:22000/tcp
      - 22000:22000/udp
      - 21027:21027/udp
    restart: unless-stopped

This means the config folder only resides inside the container in /var/syncthing/config and will be lost if something happens to the container.

Can I safely add another line under Volumes in my docker-compose.yml file like this:

  - /path/to/host/config/folder:/var/syncthing/config

and recreate the container? I wonder if this would mount the existing folder to the host folder, keeping all content, or instead the empty host folder will be mounted into the config folder, destroying the content?

This isn’t specific to syncthing, but rather applies to all Docker containers:

The filesystem used by a Docker container is lost when the docker container is deleted (except for volumes and bind mounts since those aren’t part of the container’s filesystem), so if you want to extract any data from a container’s overlayfs you need to do so before destroying it.

For syncthing specifically, by default the Dockerfile creates a volume for the config location. This volume gets created automatically on container creation and persists even if the container is destroyed. If you don’t specifiy anything in docker run/docker-compose, this will be an anonymous volume. Additionally for docker-compose, the compose documentation mentions that

In the absence of having named volumes with specified sources, Docker creates an anonymous volume for each task backing a service. Anonymous volumes do not persist after the associated containers are removed.

But I couldn’t reproduce that in a quick test. But Docker is Docker, so who knows what it’s really doing :man_shrugging:

I would mount a new volume called TEMP to wherever you want to store the config. Then open a terminal inside the docker and copy the enter config folder (which only resides inside the container, to the TEMP mount so the config files are all available outside. Then I would stop the container, rename the volume to config and relaunch. If you use the right names and paths then syncthing should end up pointing to the config on the external volume. Then your config should survive the reset.

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