|
| 1 | +## Docker |
| 2 | + |
| 3 | +This project contains a docker-compose.yml file suitable for development purposes. It will start a PostgreSQL database, minio (S3 compatible storage) and a backup container. |
| 4 | + |
| 5 | +Because all the bash scripts are mounted to root `/` the docker-compose file mounts them all individually. If you wish to add new files, create it then add it to the backup container mounts. |
| 6 | + |
| 7 | +To start the containers run: |
| 8 | + |
| 9 | +```bash |
| 10 | +docker-compose up |
| 11 | +``` |
| 12 | + |
| 13 | +Once all 3 containers start they will create three folders that are **not** tracked by git: |
| 14 | + |
| 15 | +- `./pg-data` - PostgreSQL database |
| 16 | +- `./minio-data` - Minio storage |
| 17 | +- `./backup` - Backup data |
| 18 | + |
| 19 | +Add this shell (bash or zsh) alias, it helps to quickly connect to a container by name: |
| 20 | + |
| 21 | +```bash |
| 22 | +dcon='function _dcon(){ docker exec -i -t $1 /bin/bash -c "export COLUMNS=`tput cols`; export LINES=`tput lines`; exec bash"; };_dcon' |
| 23 | +``` |
| 24 | + |
| 25 | +Use `docker ps` to list all running containers and then use `dcon <container_name>` to connect to the container. |
| 26 | + |
| 27 | +```bash |
| 28 | +dcon backup-container-postgresql-1 |
| 29 | +``` |
| 30 | + |
| 31 | +### Protips 🤓 |
| 32 | + |
| 33 | +- More modern version fo docker-compose do not require the hyphen. Try using `docker compose up`. |
| 34 | +- This bash one-liner was used to add all the files to the backup container volumes `ls docker/ | grep 'backup\.' | awk '{ print "- ./docker/"$1":/"$1 }'` |
| 35 | + |
| 36 | +## Postgres |
| 37 | + |
| 38 | +Connect to the postgres container using the `dcon` alias noted above and create the database, schema and then load in some sample data. |
| 39 | + |
| 40 | +Connect to the postgres container: |
| 41 | + |
| 42 | +```bash |
| 43 | +dcon backup-container-postgresql-1 |
| 44 | +``` |
| 45 | + |
| 46 | +Run the `psql` command to connect to the database and create the database: |
| 47 | + |
| 48 | +```bash |
| 49 | +psql -U postgres |
| 50 | +create database sakila; |
| 51 | +^D |
| 52 | +``` |
| 53 | + |
| 54 | +Run the following two commands to create the schema and insert the data. If `curl` is not installed run `apt-get update && apt-get install curl` first. |
| 55 | + |
| 56 | +```bash |
| 57 | +curl -sSL https://raw.githubusercontent.com/jOOQ/sakila/main/postgres-sakila-db/postgres-sakila-schema.sql | psql -U postgres -d sakila; |
| 58 | +``` |
| 59 | + |
| 60 | +```bash |
| 61 | +curl -sSL https://raw.githubusercontent.com/jOOQ/sakila/main/postgres-sakila-db/postgres-sakila-insert-data.sql | psql -U postgres -d sakila; |
| 62 | +``` |
| 63 | + |
| 64 | +You should now have a sample database with data. |
0 commit comments