4
2

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 1 year has passed since last update.

Next.jsが入ったコンテナからローカルのSupabaseコンテナに疎通確認するまで

Posted at

詰まったので知見として残しておきます

Supabaseコンテナの起動

% supabase start
Seeding data supabase/seed.sql...
Started supabase local development setup.

         API URL: http://localhost:54321
     GraphQL URL: http://localhost:54321/graphql/v1
          DB URL: postgresql://postgres:postgres@localhost:54322/postgres
      Studio URL: http://localhost:54323
    Inbucket URL: http://localhost:54324

ホストからはpostgresql://postgres:postgres@localhost:54322/postgresでDBにアクセスできる
しかし,NextコンテナからDBにアクセスするにはSupabaseコンテナと同一ネットワークに配置させる必要がある

supabase startするとSupabaseコンテナはsupabase_network_<project_name>というネットワークに割り当てられる
このネットワークにdocker-composeでNextコンテナを所属させる

docker-compose.yml

services: 
  next: 
    
    
    networks:
      - supabase_network_<project_name>

networks:
  supabase_network_<project_name>:
    external: true

疎通確認

コンテナ間の通信ではipアドレスではなくDockerホスト名を指定する

% docker compose exec next /bin/sh
/app # ping -c 3 supabase_db_<project_name>
PING supabase_db_<project_name> (192.168.128.2): 56 data bytes
64 bytes from 192.168.128.2: seq=0 ttl=64 time=0.560 ms
64 bytes from 192.168.128.2: seq=1 ttl=64 time=0.139 ms
64 bytes from 192.168.128.2: seq=2 ttl=64 time=0.198 ms

--- supabase_db_<project_name> ping statistics ---
3 packets transmitted, 3 packets received, 0% packet loss
round-trip min/avg/max = 0.139/0.299/0.560 ms

Postgresへの接続

SupabaseのDBコンテナは54322:5432でフォワードされているので,コンテナの5432番にアクセス

# psql 'postgresql://postgres:postgres@supabase_db_<project_name>:5432/postgres'             
psql (15.2 (Debian 15.2-1.pgdg110+1), server 15.1 (Ubuntu 15.1-1.pgdg20.04+1))
Type "help" for help.

postgres=> 

54322番ではなく5432番にアクセスすることに注意.NextコンテナでDATABASE_URLみたいなものを設定するときも5432番を指定する

完了

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?