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?

docker compose でPostgreSQL

Posted at

docker-compose でPostgreSQLを立ち上げ、ポート番号を変更してみる

インストール(例)

dnf -y remove podman runc
curl https://download.docker.com/linux/centos/docker-ce.repo -o /etc/yum.repos.d/docker-ce.repo
sed -i -e "s/enabled=1/enabled=0/g" /etc/yum.repos.d/docker-ce.repo
dnf --enablerepo=docker-ce-stable -y install docker-ce
systemctl enable --now docker


wget -O /usr/local/bin/docker-compose https://github.com/docker/compose/releases/download/v2.29.7/docker-compose-linux-x86_64

chmod +x /usr/local/bin/docker-compose

ディレクトリ構成(例)

├ db (/var/lib/postgresql/data)
└ docker-compose.yml

docker-compose.yml の内容

services:
  postgres:
    image: postgres:15.8
    container_name: postgres
    ports:
      - 15432:5432
    restart: always
    environment:
      - POSTGRES_PASSWORD=postgres
    volumes:
      - ./db:/var/lib/postgresql/data

image: 15.8のバージョンを指定
ports: 15432は外側のポート番号。ここにクライアント側から接続する
volumes: 右側のディレクトリが、実体のどこになるかという風に記載する
 ./db:/var/lib/postgresql/data :PostgreSQLのデータが入る場所

起動

docker-compose up -d postgres

接続例

psql -U postgres -h 127.0.0.1 --port 15432

注:-h localhostだとうまくつながりません。(ネットワーク経由にならない模様)

停止

docker-compose down
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?