dlbunker / ps-first-spring-boot-app

143 stars 413 forks source link

Readme - Application Database Setup #3

Closed mmoody1977 closed 4 years ago

mmoody1977 commented 4 years ago

I found that I had to use the following commands to setup the database after starting the docker container on my windows system: docker exec -it containerid /bin/bash createdb -U postgres conference_app psql -U postgres -d conference_app -f create_tables.sql psql -U postgres -d conference_app -f insert_data.sql

jt6point6 commented 4 years ago

On a Mac I have to do:

docker exec -it containerid /bin/bash
createdb -U postgres conference_app
psql -U postgres -d conference_app

And after that I copied and pasted the content of create_tables.sql and insert_data.sql

NaegelCy commented 4 years ago

Hi folks,

I am still struggling with database creation on docker. I added a bind mount where I stored my .sql files on container creation process : docker create --name postgres-demo -e POSTGRES_PASSWORD=Welcome -p 5432:5432 -v c:/Users/[my user]/postgres:/data postgres:11.5-alpine.

When I run docker exec -ti postgres-demo bash I can get the files in /data using ls -ltr data. Unfortunately when I run docker exec -ti postgres-demo psql -U postgres and try ! ls -ltr data there is no result. Consequently I am still wondering how to create tables and isert data into them without being able to access those scripts.

Please help me as I want to learn about Spring boot and this is currently impossibe to me due to lack of knowledge I have with Docker.

Thanks,

Cyril

ducreuxr commented 4 years ago

@jt6point6's solution works for me on linux (Ubuntu 20.04)

dlbunker commented 4 years ago

@NaegelCy See the instructions added at the bottom of the readme file for loading files into your docker container.

https://github.com/dlbunker/ps-first-spring-boot-app/tree/master/database/postgresql