Skip to content

Docker and DDagen‐db

Viktor Rönnbacka Nybäck edited this page Feb 27, 2024 · 11 revisions

Setup local database

If you don't need persistence, the command for a temporary database can be found in the README page. If you need persistence in you local database, create a local folder to where the database will be saved. It's recommended to not create this folder in the Github directory as the data should not be pushed to Github.

Start the persistent database with this command:

docker run --name ddagen-db -p 5432:5432 \
    -e POSTGRES_PASSWORD=ddagen \
    -e POSTGRES_DB=ddagen \
    -e POSTGRES_USER=ddagen \
    -v <path to persistence folder>:/var/lib/postgresql/data \
    postgres

Import data

In order to import data into the database start container with persistence and also add the .sql file into the database: (change the "dumpfile.sql" to your dumpfile name)

docker run --name ddagen-db -p 5432:5432 \
    -e POSTGRES_PASSWORD=ddagen \
    -e POSTGRES_DB=ddagen \
    -e POSTGRES_USER=ddagen \
    -v <path to persistence folder>:/var/lib/postgresql/data \
    -v <path to dumpfile.sql>:/mnt/ \
    postgres

After starting the container, this command can be used to import the data into the database (keep in mind this command will remove your existing database and create a new one) docker exec -it ddagen-db pg_restore -C -d ddagen -U ddagen --clean /mnt/<dumpfile.sql>

Accessing the database container

To access the commandline of the local container you can ssh into it using docker exec -it --user root ddagen-db /bin/bash

Alternative

Note that this was done on windows running docker desktop

If the method above doesn´t work for some reason test the following instead:

Create and Mount the postgres database using

docker run --name ddagen-db -p 5432:5432 \
    -e POSTGRES_PASSWORD=ddagen \
    -e POSTGRES_DB=ddagen \
    -e POSTGRES_USER=ddagen \
    -v /absolute/path/to/folder:/docker-entrypoint-initdb.d \
    postgres

To access the container

docker exec -it ddagen-db bash

To login to the database

psql -U ddagen ddagen

Note: Worth mentioning is that the version of the database might be outdated or out of sync with what the front-end expects and such there might be version errors or other issues with the database responding with NOT FOUND.

Clone this wiki locally