Docker Compose Collection Optimized for Synology
This repository will contain all the Dockerized software I currently use, have used in the past or just briefly tested.
The way I format my compose files
Each compose file should contain as much variables as possible so in the event of an update to the compose file there is no extra work to replace it with the new file as all the changes are still in the .env file.
Parts with an asterisk (*) should be always present.
container_name*
container_name: ${APP_CONTAINER_NAME:-App}
hostname
Should only be added if the desired hostname is different from the service name.
hostname: app
image*
Docker Hub is always the prefered location to use for images. If there is no image hosted there, or the current image is not maintained, services like ghcr.io might be used as well but alway as a second choice.
image: publisher/app:${APP_TAG:-latest}
The latest tag is the preferred tag.
user
user: ${UID:-1024}:${GID:-101}
Alway try to use the UID and GID of the default admin account in one form or another when there are folders to be mounted. In this example under user should be the preferred way but will not always work. Another way is trhough environment variables.
If there is no way to set the owner of the files to be created by the container then ommit the use of it altogheter.
restart*
Unless-stopped is the preferred restart policy.
restart: ${RESTART:-unless-stopped}
network_mode
network_mode: host
If there is no reason to set the network mode to something other than bridge then ommit the use of this part. Bridge (nothing set) is always the preferred way but there are containers that don't need any way in and can make use of the following.
network_mode: none
healthcheck
If the image does not contain a health check already then implement one of the following options.
Always try to use an image specific healthcheck, if available.
Use curl
healthcheck:
test: curl -f http://localhost:80/ || exit 1
Use wget
healthcheck:
test: wget --no-verbose --tries=1 --spider http://localhost:80/
If none of the options is available then ommit the use of a health check.
environment
environment:
UID: ${UID:-1024}
GID: ${GID:-101}
TZ: ${TZ:-Europe/Amsterdam}
APP_VARIABLE_NAME: ${APP_VARIABLE_NAME:-variable}
UID (User ID), GID (Group ID) and TZ (TimeZone) should always use these variable names, see example below. This is so that if there is a change in one of them it will be the new value in all services in the stack (if there is more than 1).
environment:
APP_UID: ${UID:-1024}
APP_GID: ${GID:-101}
TIMEZONE: ${TZ:-Europe/Amsterdam}
Other environment variables should always be prefixed by the name of the application. An abbreviation to a application name should be replaced by the full name. See example below.
environment:
VARIABLE1: ${APP_VARIABLE1:-variable1}
APP_VARIABLE2: ${APP_VARIABLE2:-variable2}
A_VARIABLE3: ${APP_VARIABLE3:-variable3}
ports
ports:
- ${APP_PORT:-80}:80
If there is only one port available use the variable name as in the example above. If there are multiple ports try to use a short desription for all of them. See the example below.
ports:
- ${APP_PORT_HTTP:-80}:80
- ${APP_PORT_SSH:-22}:22
volumes
volumes:
- /${SYNOLOGY_VOLUME:-volume1}/docker/${STACK_NAME:-stack}/${APP_CONTAINER_NAME:-App}/config:/config
The files and folders for the image should be stored in the following folder: /volume1/docker/stack/App
Only the docker folder in here is a fixed folder as this folder is created by Synology as default folder for Docker.
All files and folders mounted in the container should be in its correct subfolders under the folder mentioned before. For instance:
| Container | Host |
|---|---|
| /config | /volume1/docker/stack/App/config |
| /config.json | /volume1/docker/stack/App/config.json |
| subfolder/config | /volume1/docker/stack/App/subfolder/config |
| subfolder/config.json | /volume1/docker/stack/App/subfolder/config.json |