Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
dev:web:psql_docker [2023/03/03 11:21] – initial mbdev:web:psql_docker [2023/03/03 12:21] (current) mb
Line 7: Line 7:
  
 ===== create dockerfile and container ===== ===== create dockerfile and container =====
-<Code: shell linenums:1 |Dockerfile>FROM postgres+firstly we create a dockerfile using the postgres docker image and copying the exported database into the new image. \\ 
 +<Code: shell linenums:1 | Dockerfile>FROM postgres
 COPY fsidb_bac.sql /docker-entrypoint-initd.d/</Code> COPY fsidb_bac.sql /docker-entrypoint-initd.d/</Code>
 +to build the dockerfile use: <Code: shell linenums:0|>docker build -t fsidbpostgresql:latest . </Code>
 +With //docker images// all locally saved images are shown and fsidbpostgresql:latest should now be visible. \\
 +Now we start the container using:
 +<Code: shell linenums:0|>sudo docker run -d --name postgresfsidb -p 5432:5432 -e POSTGRES_PASSWORD=MySafePassword fsidbpostgresql:latest </Code>
 +Make sure the port isn't already used on your docker hostsystem, if so you can bind 5432 onto another port of the hostsystem. \\
 +===== import database in container =====
 +Firstly connect to the shell of the docker container. All containers can be listed with //docker container ls -a//.
 +<Code shell linenums:0|>docker exec -it postgresfsidb bash</Code>
 +Before importing the fsidb_bac.sql a new database has to be created. Usercreation is optionally. \\
 +Start postgresql client:
 +<Code shell linenums:0|>psql -U postgres </Code>
 +Create a new database with sql statement:
 +<Code sql linenums:0|>CREATE DATABASE newdb;</Code>
 +Quit the postgresql client with **\q** \\
 +Import the database as following:
 +<Code shell linenums:0|>psql -U postgres newdb < /docker-entrypoint-initd.d/fsidb_bac.sql</Code>