For a majority of applications you should just use Postgresql. I know I'm writing for an audience that loves their Datomics and XTDBs, but the rest of this is focused on the Postgresql life path.
If you get to the end I'm sure it would be clear how you would slot in your alternative database of choice.
docker-compose.yaml
file and put the following into it.This will let us start an instance of Postgres on the correct version for everyone working on the code.
In addition,
it can be helpful when there are changes that require a wipe or a restart to have all your data be in a
project-local folder like
./data/db
.
services:
postgres:
image: postgres:17
restart: unless-stopped
env_file: ".env"
healthcheck:
test: ['CMD-SHELL', "sh -c 'pg_isready -U postgres -d postgres'"]
interval: 3s
timeout: 3s
retries: 10
environment:
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
volumes:
- ./data/db:/var/lib/postgresql/data
ports:
- '5432:5432'
.env
and put the
following into it.
POSTGRES_PASSWORD=postgres
.env
to a .gitignore
file.The rest of will try to not be git
specific, but this one in particular is worth calling
out.
Accidentally
commiting a .env
file is one of those things that's easy to do by mistake if you are not
careful. And its
important not to, because you can leak API keys and similar that way.
Also, while we're at it, add .cpcache
, .clj-kondo/.cache
, and data
to
your .gitignore
. .cpcache
folder
comes from the clojure CLI tools and isn't usefully sharable between machines.
.clj-kondo/.cache
is similar temporary files from the linter. data
is where
all
the data from the local postgres instance will go.
.env
.cpcache
.clj-kondo/.cache
data
docker compose up -d
This should download start up postgres in the background.
Note that, as of the time of writing, the version of docker where you run docker compose
is relatively new. Older docker versions will want you to run docker-compose
. That is, one
command with the hyphen.
Make sure you have a new enough version of docker.