Opinionated Guide to Docker Host the Sync Server
PostgreSQL 16
Get UID & GID
First start the DB to get the UID & GID needed for the init files.
Store the secrets somewhere. E.g. in ~/docker-server-env/postgresql:
secrets:
USER=pgdbuser
PASSWD=THE_ATUIN_PASSWORD
Then let’s start the default PostgreSQL container. No volume mounts for data, as we want to discard it anyway:
cd ~/docker-server-env/postgresql
. ./secrets
docker run -d \
--name postgresql-16 \
-p 5432:5432 \
--restart unless-stopped \
--network internal-docker-net \
-e POSTGRES_USER=${USER} \
-e POSTGRES_PASSWORD=${PASSWD} \
-e POSTGRES_DB=mydbname \
postgres:16-bullseye
docker logs postgresql-16
Now let’s get the UID & GID needed:
# get the user ID of the user running the process
docker top postgresql-16
# was 999 for the process postgres
# get the user name
docker exec -it postgresql-16 /bin/bash
cat /etc/passwd | grep 999
# got the line for the user postgres for the group id
cat /etc/group | grep postgres
# hence, this is what we want: 999:999
exit
# let's clean up
docker stop postgresql-16
docker rm postgresql-16
Note down the UID & GID somewhere for later.
PostgreSQL init files
In the folder docker-host:/home/user/docker-server-env/postgresql/initdb.d/ create your init scripts like 01_atuin_db_init.sh:
#!/bin/bash
set -e
DB_NAME=atuin
echo "Creating database: ${DB_NAME}"
psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL
CREATE USER ${DB_NAME};
ALTER USER ${DB_NAME} WITH PASSWORD 'a2GnQtpTzdUrnHTsPjpmURP2wPbMrt7U2fUg3';
CREATE DATABASE ${DB_NAME};
GRANT ALL PRIVILEGES ON DATABASE ${DB_NAME} TO ${DB_NAME};
EOSQL
and to restore backups at later points, when you start a new PostgreSQL version 02_atuin_data.sql:
-- paste import statements here to apply a backup to a new db
To allow execution in the container, we need to fix the ownership to the UID & GID noted down in the last section and file permissions:
cd ~/docker-server-env/postgresql
sudo chown 999:999 initdb.d/*
sudo chmod u+x initdb.d/*
Start and initialise the DB
cd ~/docker-server-env/postgresql
docker volume create postgresql-data
. ./secrets
docker run -d \
--name postgresql-16 \
-p 5432:5432 \
--restart unless-stopped \
--network internal-docker-net \
--mount 'type=volume,src=postgresql-data,destination=/var/lib/postgresql/data' \
--mount 'type=bind,src=/home/user/docker-server-env/postgresql/initdb.d,destination=/docker-entrypoint-initdb.d' \
-e POSTGRES_USER=${USER} \
-e POSTGRES_PASSWORD=${PASSWD} \
-e POSTGRES_DB=mydbname \
postgres:16-bullseye
docker logs postgresql-16
In the log look out for ERRORs…
Test the connection with the newly created user to it’s DB:
psql -h docker-host-01 -U atuin
In case something went wrong, delete everything and start from scratch again:
docker stop postgresql-16
docker rm postgresql-16
docker volume rm postgresql-data
docker volume create postgresql-data
PGAdmin for Admin tasks
# create volumes
docker volume create pgadmin
# start
docker run -d \
--name pgadmin4 \
--restart unless-stopped \
--network internal-docker-net \
--mount 'type=volume,src=pgadmin,destination=/var/lib/pgadmin' \
-e "PGADMIN_DEFAULT_EMAIL=name@example.com" \
-e "PGADMIN_DEFAULT_PASSWORD=GET_CREATIVE" \
-d \
dpage/pgadmin4
# to update
docker stop pgadmin4
docker rm pgadmin4
# and execute the run from before
Atuin setup
Reference: Atuin server config
Then to run an own sync server:
ssh user@docker-host-01.sub.example.com
cd docker-server-env/atuin-sync-server
Create the config file server.toml:
host = "0.0.0.0"
port = 8888
open_registration = true
db_uri="postgres://pgdbuser:THE_ATUIN_PASSWORD@postgresql-16:5432/atuin"
And start the db for real
docker run -d \
--name atuin-sync-server \
--restart unless-stopped \
--mount 'type=bind,src=/home/user/docker-server-env/atuin-sync-server/server.toml,target=/config/server.toml' \
-p 8888:8888 \
--network internal-docker-net \
ghcr.io/atuinsh/atuin:18.0.1 \
server start
# for error search add: -e ATUIN_LOG=debug -e RUST_LOG=debug
login to register a new atuin installation to my own sync server: atuin register
I hope this helps someone.