-
Notifications
You must be signed in to change notification settings - Fork 3
Docker and DDagen‐db
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
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 --no-owner --role=ddagen /mnt/<dumpfile.sql>
To access the commandline of the local container you can ssh into it using docker exec -it --user root ddagen-db /bin/bash
If you want to utilize docker completley to manage the local instance of the database you can use the following steps.
Two key notes before we start:
This was done on windows running docker desktop
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
First start by
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
Note: If you want to access the database from the commandline run the following two commands in order
docker exec -it ddagen-db bash
psql -U ddagen ddagen
To then setup pgAdmin as opposed to using the commandline from the code above, to the following
Install pgAdmin as a docker container run
docker pull dpage/pgadmin4
Then to spin up the containter do
docker run -p 80:80 \
-e 'PGADMIN_DEFAULT_EMAIL=user@domain.com' \
-e 'PGADMIN_DEFAULT_PASSWORD=SuperSecret' \
-d dpage/pgadmin4
To then access the container goto http://localhost:80
Now we need to add the ddagen-db server to out admin page, First under the object explorer on the left rightklick server and the klick register and choose server, now you get a window where you need to fill in some forms, under the first tab General just pick a suitable name, then goto the Connection tab. Here the fill in the following:
Host name/address: host.docker.internal //this is because we are accessing a docker container from another docker container, for unix this might be just localhost, not sure.
port: 5432 //should be by default
Maintenance database: ddagen
Username: ddagen
Password: ddagen
Leave everything else as is, press save. You should now be able to the pgAdmin page for the ddagen database running from you local container. If it doesn´t work ensure that the port your trying to access is the same as the ddagen-db is mounted to. If you still get stuck ask your fellow GPT AI for help, prefarably using the two docker run
commands as reference