How am I supposed to use a Postgresql docker image/container? -


i'm new docker. i'm still trying wrap head around this.

i'm building node application (rest api), using postgresql store data.

i've spent few days learning docker, i'm not sure whether i'm doing things way i'm supposed to.

so here questions:

  1. i'm using official docker postgres 9.5 image base build own (my dockerfile adds plpython on top of it, , installs custom python module use within plpython stored procedures). created container suggedsted postgres image docs:

    docker run --name some-postgres -e postgres_password=mysecretpassword -d postgres

    after stop container cannot run again using above command, because container exists. start using docker start instead of docker run. normal way things? use docker run first time , docker start every other time?

  2. persistance: created database , populated on running container. did using pgadmin3 connect. can stop , start container , data persisted, although i'm not sure why or how happening. can see in dockerfile of official postgres image volume created (volume /var/lib/postgresql/data), i'm not sure that's reason persistance working. please briefly explain (or point explanation) how works?

  3. architecture: read, seems appropriate architecture kind of app run 3 separate containers. 1 database, 1 persisting database data, , 1 node app. way it? how using data container improve things? afaik current setup working ok without one.

  4. is there else should pay atention to?

thanks

edit: adding confusion, ran new container debian official image (no dockerfile, docker run -i -t -d --name debtest debian /bin/bash). container running in background, attached using docker attach debtest , proceeded apt-get install postgresql. once installed ran (still within container) psql , created table in default postgres database, , populated 1 record. exited shell , container stopped automatically since shell wasn't running anymore. started container againg using docker start debtest, attached , run psql again. found persisted since first run. postgresql installed, table there, , offcourse record inserted there too. i'm confused why need volume persist data, since quick test didn't use 1 , apears work fine. missing here?

thanks again

1.

docker run --name some-postgres -e postgres_password=mysecretpassword -d postgres

after stop container cannot run again using above command, because container exists.

correct. named (--name some-postgres) hence before starting new one, old 1 has deleted, e.g. docker rm -f some-postgres

so start using docker start instead of docker run. normal way things? use docker run first time , docker start every other time?

no, no means normal docker. docker process containers supposed ephemeral, thrown away , started anew.

  1. persistance: ... can stop , start container , data persisted, although i'm not sure why or how happening. ...

that's because reusing same container. remove container , data gone.

  1. architecture: read, seems appropriate architecture kind of app run 3 separate containers. 1 database, 1 persisting database data, , 1 node app. way it? how using data container improve things? afaik current setup working ok without one.

yes, way go having separate containers separate concerns. comes in handy in many cases, when example need upgrade postgres base image without losing data (that's in particular data container starts play role).

  1. is there else should pay atention to?

when acquainted docker basics, may take @ docker compose or similar tools run multicontainer applications easier.


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -