0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

DockerにPostgreSQLを入れる(使い捨て)

Last updated at Posted at 2019-12-21

コンテナ作成および起動

docker container run -d --rm --name postgrescon -e POSTGRES_USER=postgresusr -e POSTGRES_PASSWORD=postgrespass -p 5432:5432 postgres
オプション 意味
--name コンテナ名
-d バックグラウンド実行
--rm 停止後にコンテナ削除
-p 5432:5432 ホストのポート:コンテナのポート
-e POSTGRES_USER スーパユーザー名
-e POSTGRES_PASSWORD スーパユーザーパスワード
postgres 使用イメージ

コンテナ動作確認

$ docker container exec -it postgrescon bash

root@xxxxxx:/# psql --version
psql (PostgreSQL) 11.0 (Debian 11.0-1.pgdg90+2)

ログイン

root@xxxxxx:/# psql -U postgresusr
psql (11.0 (Debian 11.0-1.pgdg90+2))
Type "help" for help.

postgres=#

ホストからの接続確認

# psqlのためpostgresqlをインストール
$ brew install postgresql

# 自動起動停止
$ brew services stop postgresql

# 停止確認
$ brew services list

# 接続できることを確認する
$ psql -h localhost -U postgresusr
Password for user postgresusr: 
# 以下のように出ればOK
psql (12.1)
Type "help" for help.

postgresusr=# 
0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?