You are here
Home > IT > PostgreSQLをdockerで立ち上げる

PostgreSQLをdockerで立ち上げる

下記コマンドを実行する。

docker run -d -p 15432:5432 -v /Users/myuser/postgres-tmp:/var/lib/postgresql/data -e POSTGRES_HOST_AUTH_METHOD=trust --name postgres-12-alpine postgres:12-alpine

Docker Hub

https://hub.docker.com/_/postgres

オプションを順番に説明

d デタッチモード バックグラウンドで立ち上げること
p ポートフォワード ホスト側ポート -> image側ポートへ
v ホストマウント ホスト側のファイルをimage側のファイルとしてマウントする
e 環境変数 ここでは認証なしログイン設定している
12-alpine タグ。指定することにより任意のimageを使用する。

こんな感じになる。

waiting for server to start....2021-02-05 05:29:51.752 UTC [37] LOG:  starting PostgreSQL 12.5 on x86_64-pc-linux-musl, compiled by gcc (Alpine 10.2.1_pre1) 10.2.1 20201203, 64-bit
2021-02-05 05:29:51.754 UTC [37] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
2021-02-05 05:29:51.794 UTC [38] LOG:  database system was shut down at 2021-02-05 05:29:49 UTC
2021-02-05 05:29:51.817 UTC [37] LOG:  database system is ready to accept connections
 done
server started

/usr/local/bin/docker-entrypoint.sh: ignoring /docker-entrypoint-initdb.d/*

2021-02-05 05:29:52.089 UTC [37] LOG:  received fast shutdown request
waiting for server to shut down....2021-02-05 05:29:52.091 UTC [37] LOG:  aborting any active transactions
2021-02-05 05:29:52.092 UTC [37] LOG:  background worker "logical replication launcher" (PID 44) exited with exit code 1
2021-02-05 05:29:52.093 UTC [39] LOG:  shutting down
2021-02-05 05:29:52.146 UTC [37] LOG:  database system is shut down
 done
server stopped

PostgreSQL init process complete; ready for start up.

2021-02-05 05:29:52.213 UTC [1] LOG:  starting PostgreSQL 12.5 on x86_64-pc-linux-musl, compiled by gcc (Alpine 10.2.1_pre1) 10.2.1 20201203, 64-bit
2021-02-05 05:29:52.213 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432
2021-02-05 05:29:52.213 UTC [1] LOG:  listening on IPv6 address "::", port 5432
2021-02-05 05:29:52.219 UTC [1] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
2021-02-05 05:29:52.272 UTC [49] LOG:  database system was shut down at 2021-02-05 05:29:52 UTC
2021-02-05 05:29:52.296 UTC [1] LOG:  database system is ready to accept connections

コメントを残す

Top