Postgresql and Docker -


we have application splitted in several git repositories:

  1. webapp git repository (django + postgres + celery)
  2. workers (python + celery)

with need rabbitmq-server. able dockerize first webapp had questions dockerisation , more postgres.

today have 1 database, used our webbapp. database created in postgres container using script placed in /docker-entrypoint-initdb.d specified in official postgres container.

if tomorrow, have second web apps, need use postgres database, absolutely need modify current postgres container create new database ? better create new postgres container particular database? , 1 thing have difficulties with: data in container not persistent. data written in postgres container destroyed when container stopped. docker's compliant solution keep thoses data persistent ?

thanks help.

you should use data volume make data persistent.

docker run -v /var/lib/postgresql/data --name dbdata busybox /bin/true docker run --volume-from dbdata postgresql # , additional parameters 

to create new database, can enter container using nsenter

# start shell in container ne() {  pid=$(docker inspect --format '{{.state.pid}}' $1)  env shell='/bin/bash' sudo -e nsenter --target $pid \   --mount --uts --ipc --net --pid } 

ne my_postgresql_container

(reference: http://docs.blowb.org/setup-host/docker.html)

you can save function .bashrc file if want use more frequently.

inside there, start postgresql client , run sql statements create database.


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -