LoginSignup
28
36

More than 5 years have passed since last update.

公式Dockerイメージ PostgreSQL メモ

Last updated at Posted at 2018-10-17

筆者環境

  • Docker for Mac Version 2.0.0.0-beta1-mac75 Channel Edge

初期設定

  • ユーザ postgres
  • データベース postgres

については何も定義しなくても最初から存在している。
コンテナを動かすにはこれらに加えて最低限postgresユーザのパスワードを設定する必要がある。

docker run -d -e POSTGRES_PASSWORD=mysecretpassword postgres:10-alpine

永続化

/var/lib/postgresql/data をマウントする。

docker run -d -e POSTGRES_PASSWORD=secret -v `pwd`/pgsql-data:/var/lib/postgresql/data postgres:10-alpine

Docker Compose

postgresユーザのパスワードの設定、永続化、ポートフォワードの設定を行った場合。

docker-compose.yml
version: '3'
services:
  postgres:
    image: postgres:10-alpine
    # 任意のパスワード
    environment:
      POSTGRES_PASSWORD: secret
    # ホスト側は任意のディレクトリ
    volumes:
      - ./pgsql-data:/var/lib/postgresql/data
    # ホスト側は任意のポート
    ports:
      - 5432:5432

起動する場合は、 docker-compose.yml のあるディレクトリで、

docker-compose up -d

を実行。

接続

上記 docker-compose.yml 設定の場合、ホスト環境からの接続は、

  • ホスト localhost
  • ポート 5432
  • データベース postgres
  • ユーザ postgres
  • パスワード secret

を指定することで接続できる。

28
36
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
28
36