LoginSignup
6
2

More than 1 year has passed since last update.

Docker PostgreSQL を起動するコマンド

Last updated at Posted at 2021-06-05

最近は docker-compose.yaml で起動することもあって、ターミナルから起動することがあまりなく、ロケール設定とかタイムゾーンを忘れてしまうのでメモっておく

起動する

docker run --name postgres \
           -e POSTGRES_PASSWORD=password \
           -e POSTGRES_INITDB_ARGS="--encoding=UTF8 --no-locale" \
           -e TZ=Asia/Tokyo \
           -v postgresdb:/var/lib/postgresql/data \
           -p 5432:5432 \
           -d postgres

確認する

# コンテナにアクセスする
docker exec -it postgres /bin/bash

# PostgreSQL にログインする
psql -h localhost -U postgres

# locale確認
postgres-# \l
                             List of databases
   Name    |  Owner   | Encoding | Collate | Ctype |   Access privileges   
-----------+----------+----------+---------+-------+-----------------------
 postgres  | postgres | UTF8     | C       | C     | 
 template0 | postgres | UTF8     | C       | C     | =c/postgres          +
           |          |          |         |       | postgres=CTc/postgres
 template1 | postgres | UTF8     | C       | C     | =c/postgres          +
           |          |          |         |       | postgres=CTc/postgres
(3 rows)

# TimeStamp確認
postgres=# select NOW();
              now              
-------------------------------
 2021-06-05 22:08:55.231972+09
(1 row)

# 抜ける
\q
exit

終わり

6
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
2