sexta-feira, 2 de junho de 2017

DOCKER Faq, HowTo, Referece, Sample Install Run PostgreSQL in a Docker

1. Introduction

This post gathers information about PostgreSQL and Docker.


2. Step-by-Step


2.1. Ensure Docker, Docker Compose are working

# docker --version
Docker version 17.03.1-ce, build c6d412e
# docker-compose --version
docker-compose version 1.11.2, build dfed245

2.2. Install a PostgreSQL Docker

  • Determining PostgreSQL Docker Version to install

# psql --version
psql (PostgreSQL) 9.6.3


  • Pull docker image versions

# docker pull postgres:9.6.3-alpine
# docker pull postgres:9.6.3


  • Run PostgreSQL Docker Image in background - database instance

# docker run --name postgres-01 -e POSTGRES_PASSWORD=mysecretpassword -d postgres:9.6.3-alpine
# docker run --name postgres-02 -e POSTGRES_PASSWORD=mysecretpassword -d postgres:9.6.3


  • Check both Docker process images running 

# docker ps
CONTAINER ID        IMAGE                   COMMAND                  CREATED             STATUS              PORTS               NAMES
676278f9f054        postgres:9.6.3          "docker-entrypoint..."   7 seconds ago       Up 7 seconds        5432/tcp            postgres-02
0d93213e347e        postgres:9.6.3-alpine   "docker-entrypoint..."   12 seconds ago      Up 11 seconds       5432/tcp            postgres-01


  • Stop Docker instance "postgres-02"

# docker stop postgres-02
# docker kill postgres-02


  • Run PostgreSQL psql command line, linked to running instance "postgres-01", using interative mode. Interate with application saying the password "mysecretpassword"

# docker run --name postgres-psql-01 -it --rm --link postgres-01:postgres postgres psql -h postgres-01 -U postgres:9.6.3-alpine
Password for user postgres: mysecretpassword
psql (9.6.3)
Type "help" for help.

postgres=# select current_date;
    date
------------
 2017-06-03

(1 row)

postgres=# \q



  • Run PostgreSQL plsql command line, linked to running instance "postgres-01", using interative mode, using password in command line





3. References



Nenhum comentário:

Postar um comentário