This content originally appeared on DEV Community and was authored by suin
Syncthing is a powerful file synchronization tool, and when combined with Docker Compose, it becomes even easier to manage and deploy. This guide will walk you through the process of setting up and running Syncthing using Docker Compose, from initial setup to troubleshooting common issues.
1. Preparation
First, let's create a directory for Syncthing:
mkdir -p ~/data
Note: Creating this directory in advance helps prevent permission issues later on.
2. Creating the docker-compose.yml File
Create a docker-compose.yml
file in your home directory with the following content:
services:
syncthing:
image: syncthing/syncthing
container_name: syncthing
hostname: my-linux
environment:
- PUID=1000
- PGID=1000
volumes:
- ./data:/var/syncthing
network_mode: host
restart: unless-stopped
Explanation of Configuration
Let's break down the key components of this configuration:
-
container_name: syncthing
- This sets a friendly name for your container, making it easier to manage in your Docker environment.
-
hostname: my-linux
- This will be used as Syncthing's node name. Choose a name that's easily identifiable on your network.
-
environment
:-
PUID=1000
andPGID=1000
- These set the user and group IDs for the container.
- This ensures that files created within the container match your host user's permissions.
- Replace these values with your actual UID and GID, which you can find by running
id -u
andid -g
on your host machine.
-
-
volumes
:- ./data:/var/syncthing
- This mounts the
./data
directory from your host to/var/syncthing
in the container. - This setup persists Syncthing's data and configuration, even if the container is recreated.
-
network_mode: host
- This allows the container to use the host's network stack.
- It enables Syncthing to properly detect other devices on your local network.
-
restart: unless-stopped
- This ensures that the container automatically restarts if the Docker daemon restarts or if your host machine reboots.
- However, it won't restart if you manually stop the container.
3. Starting the Container
Launch the container with this command:
docker-compose up -d
4. Troubleshooting
Certificate Generation Error
If you encounter an error like this:
Failed to load/generate certificate: save cert: open /var/syncthing/config/cert.pem: permission denied
It's likely due to a permissions issue with the ~/data
directory. Here's how to fix it:
- Check the directory ownership:
ls -la ~/data
- Change the ownership to your user:
sudo chown -R $(id -un):$(id -gn) ~/data
Conclusion
By following these steps, you can easily set up and run Syncthing using Docker Compose. This method simplifies the management of Syncthing and integrates well with other Docker-based applications.
For more detailed information on configuring and using Syncthing, refer to the official Syncthing documentation.
This content originally appeared on DEV Community and was authored by suin
suin | Sciencx (2024-07-15T01:45:19+00:00) How to Easily Run Syncthing with Docker Compose. Retrieved from https://www.scien.cx/2024/07/15/how-to-easily-run-syncthing-with-docker-compose/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.