Docker and PostgreSQL

Post Reply
Site Admin
Posts: 69
Joined: Thu Sep 24, 2020 5:40 pm

Docker and PostgreSQL

Post by Admin »

Docker and PostgreSQL

Code: Select all

docker --version

docker pull postgres:alpine

dmi@dmi-laptop:~$ docker pull postgres:alpine
alpine: Pulling from library/postgres
df20fa9351a1: Pull complete 
600cd4e17445: Pull complete 
04c8eedc9a76: Pull complete 
27e869070ff2: Pull complete 
a64f75a232e2: Pull complete 
ee71e22a1c96: Pull complete 
0ef267de4e32: Pull complete 
a61c56cdb243: Pull complete 
Digest: sha256:b05c3311616d0d798225524e351423efa01dd3e5e6b56b2cca96a64d8fd4e746
Status: Downloaded newer image for postgres:alpine

docker images

dmi@dmi-laptop:~$ docker images
REPOSITORY                    TAG                 IMAGE ID            CREATED             SIZE
postgres                      alpine              3781fe35c6b8        4 weeks ago         157MB

docker run --name postgres-0 -e POSTGRES_PASSWORD=password -d -p 5432:5432 postgres:alpine

docker ps

docker exec -it postgres-0 bash

dmi@dmi-laptop:~$ docker exec -it postgres-0 bash
bash-5.0# pwd
bash-5.0# ls
bin                         home                        opt                         sbin                        usr
dev                         lib                         proc                        srv                         var
docker-entrypoint-initdb.d  media                       root                        sys
etc                         mnt                         run                         tmp
bash-5.0# psql
psql: error: could not connect to server: FATAL:  role "root" does not exist
bash-5.0# psql -U postgres 
psql (12.4)
Type "help" for help.


postgres=# \du
                                   List of roles
 Role name |                         Attributes                         | Member of 
 postgres  | Superuser, Create role, Create DB, Replication, Bypass RLS | {}

postgres=# create database test;
postgres=# \l
                                 List of databases
   Name    |  Owner   | Encoding |  Collate   |   Ctype    |   Access privileges   
 postgres  | postgres | UTF8     | en_US.utf8 | en_US.utf8 | 
 template0 | postgres | UTF8     | en_US.utf8 | en_US.utf8 | =c/postgres          +
           |          |          |            |            | postgres=CTc/postgres
 template1 | postgres | UTF8     | en_US.utf8 | en_US.utf8 | =c/postgres          +
           |          |          |            |            | postgres=CTc/postgres
 test      | postgres | UTF8     | en_US.utf8 | en_US.utf8 | 
(4 rows)

postgres=# \c test
You are now connected to database "test" as user "postgres".
test=# \d
Did not find any relations.

Connection from a client:

dmi@dmi-laptop:~$ psql -h localhost -p 5432 -U postgres
Password for user postgres: 
psql (12.4 (Ubuntu 12.4-0ubuntu0.20.04.1))
Type "help" for help.


Post Reply