DockerのpostgreSQLの起動方法

2020年5月27日

よく忘れるのでメモしておく。

C:\Users\ebata>docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
19e323b3f7c1 postgres:12.2 "docker-entrypoint.s…" 2 months ago Exited (255) 2 months ago 0.0.0.0:5432->5432/tcp postgres122
70fa5aa3a11d pgrouting/pgrouting:v3.0.0-dev-postgresql_12 "docker-entrypoint.s…" 2 months ago Exited (255) 2 months ago 0.0.0.0:15432->5432/tcp ebata_db_1
78c979ee1238 busybox "sh" 2 months ago Exited (0) 2 months ago ebata_db_data_1
C:\Users\ebata>docker start -a postgres122
PostgreSQL Database directory appears to contain a database; Skipping initialization
2020-05-24 15:58:13.237 UTC [1] LOG: starting PostgreSQL 12.2 (Debian 12.2-2.pgdg100+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 8.3.0-6) 8.3.0, 64-bit
2020-05-24 15:58:13.250 UTC [1] LOG: listening on IPv4 address "0.0.0.0", port 5432
2020-05-24 15:58:13.250 UTC [1] LOG: listening on IPv6 address "::", port 5432
2020-05-24 15:58:13.290 UTC [1] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
2020-05-24 15:58:13.352 UTC [24] LOG: database system was interrupted; last known up at 2020-03-12 10:28:44 UTC
2020-05-24 15:58:13.535 UTC [24] LOG: database system was not properly shut down; automatic recovery in progress
2020-05-24 15:58:13.568 UTC [24] LOG: redo starts at 0/166F4D8
2020-05-24 15:58:13.569 UTC [24] LOG: invalid record length at 0/166F5C0: wanted 24, got 0
2020-05-24 15:58:13.569 UTC [24] LOG: redo done at 0/166F588
2020-05-24 15:58:13.730 UTC [1] LOG: database system is ready to accept connections
C:\Users\ebata>docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
19e323b3f7c1 postgres:12.2 "docker-entrypoint.s…" 2 months ago Up 13 minutes 0.0.0.0:5432->5432/tcp postgres122
C:\Users\ebata>docker container exec -it postgres122 bash
root@19e323b3f7c1:/# ls
bin boot dev docker-entrypoint-initdb.d docker-entrypoint.sh etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var
root@19e323b3f7c1:/# psql -U postgres
psql (12.2 (Debian 12.2-2.pgdg100+1))
Type "help" for help.
postgres-# \l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+----------+----------+------------+------------+-----------------------
ca_db | postgres | UTF8 | en_US.utf8 | en_US.utf8 |
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
(4 rows)
postgres-# \c ca_db
You are now connected to database "ca_db" as user "postgres".

その他、viを使いたければ、

root@19e323b3f7c1:/#apt-get update

root@19e323b3f7c1:/#apt-get install vim

2020年5月27日2020/05,江端さんの技術メモ

Posted by ebata