LoginSignup
0
0

More than 1 year has passed since last update.

PostgreSQLのサンプルスキーマのDockerfile化

Last updated at Posted at 2022-10-16

PostgresSQLのサンプルスキーマは、postgresqltutorial の DVD rental storeのものが有名です(DVD...、もはやイメージが湧くのか不明ですが)。

DVDレンタルのERD

これを取り込む手順を紹介した記事はたくさんありますが、Dockerfileの例が少なかったので作ってみました。
コンテナイメージサイズのeスポーツに興味がある方は、RUNをまとめるとか、apt-getでインストールした curl, zipを削除するとかzipファイルを削除するとか工夫してみても良いと思います。

Dockerfile
FROM postgres:14.3

ENV POSTGRES_USER="dvdrental"
ENV POSTGRES_PASSWORD="password"
ENV POSTGRES_DB="dvdrental"

RUN apt-get -qq update && apt-get install -y -qq curl zip
RUN curl -Os https://www.postgresqltutorial.com/wp-content/uploads/2019/05/dvdrental.zip
RUN unzip dvdrental.zip

COPY entrypoint.sh /docker-entrypoint-initdb.d/
  • URL: jdbc:postgresql://localhost:5432/dvdrental
  • ユーザー: dvdrental
  • パスワード: password

ついでにdocker-composeも共有します。

version: '3.5'

services:
  postgres:
    build:
      context: ./
      dockerfile: Dockerfile
    environment:
      POSTGRES_USER: dvdrental
      POSTGRES_PASSWORD: password
      POSTGRES_DB: dvdrental
      TZ: "Asia/Tokyo"
    ports:
      - "5432:5432"
    healthcheck:
      test: pg_isready -U dvdrental -d dvdrental
      timeout: 45s
      interval: 10s
      retries: 10

ビルド&起動する方法です。

# プロキシ設定は不要であれば、--build-arg 以下を削除ください
$ docker-compose build --build-arg http_proxy=%http_proxy% --build-arg https_proxy=%http_proxy% 
$ docker-compose up -d

気軽にお試しできる環境を用意しておくと、ちょっとしたブログを書くときに助かりますね。では、ハッピーPostgreSQLライフを!

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