4
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Laravel x Docker x pgAdmin接続メモ

Posted at

自分用メモ

これで合ってんのか分らんが、とりあえず繋がる要素は揃ってるっぽいので
自分用のメモとして忘れないうちにメモ残す。

環境

バージョン
Docker 27.1.2
PHP 8.2.26
Composer 2.8.4
psql (PostgreSQL) 15.10
Ubuntu 15.10-1

.env

.env
# pgAdmin4 server作成時設定
DB_CONNECTION=pgsql
DB_HOST=pgsql
DB_PORT=5432
DB_DATABASE=databaseName
DB_USERNAME=postgres
DB_PASSWORD=password

# pgAdmin4ログイン用
PGADMIN_EMAIL=
PGADMIN_PASSWORD=

docker-compose.yml

services内に追記

docker-compose.yml
pgadmin4:
        image: dpage/pgadmin4:8.11
        ports:
            - 8888:80
        volumes:
            - pgadmin4_data:/var/lib/pgadmin
        environment:
            PGADMIN_DEFAULT_EMAIL: '${PGADMIN_EMAIL}'
            PGADMIN_DEFAULT_PASSWORD: '${PGADMIN_PASSWORD}'
        networks:
            - sail

最下部に追記

docker-compose.yml
volumes:
    sail-pgsql:
        driver: local
    pgadmin4_data:
        driver: local

コマンド

DB選択(Laravelプロジェクト作成する時にインストール済みならパス)

sail php artisan sail:install

 ┌ Which services would you like to install? ───────────────────┐
 │ pgsql                                                        │
 └──────────────────────────────────────────────────────────────┘

image追加

docker pull dpage/pgadmin4

pgsql接続

# dockerコンテナに入る
docker compose exec laravel.test bash

# パッケージのアップデート PostgreSQL Clientのインストール
apt-get update && apt-get install -y postgresql-client  ※ 必要?


# DB接続確認
psql -h pgsql -U postgres -d databeseName
# DB_PASSWORD入力
Password for user postgres:
# 接続済み状態
psql (17.2 (Ubuntu 17.2-1.pgdg22.04+1), server 15.7 (Debian 15.7-1.pgdg120+1))

dockerビルド

docker compose build --no-cache

マイグレーションコマンド実行

php artisan migrate

pgAdmin4設定

1.http://localhost:8888にアクセス

.envファイルに設定したPGADMIN_EMAILとPGADMIN_PASSWORDを入力

スクリーンショット 2024-12-14 203659.png



2-1.サーバー新規作成

スクリーンショット 2024-12-14 203604.png


2-2.Nameを入力(自由でOK)

スクリーンショット 2024-12-14 203618.png



2-3..envで設定した値を入力して保存

スクリーンショット 2024-12-14 203633.png



3.左のServersをクリックすると作成したサーバーが確認できる!

最後に

接続値確認コマンド

DB接続確認の中でのみ有効?
\conninfo

間違っている部分があると思うので、要修正

4
1
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
4
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?