LoginSignup
0
0

More than 3 years have passed since last update.

dockerのpostgresqlに直接接続する方法

Posted at

dockerからpostgresqlに直接繋ぐ方法です。

コンテナ内に入ってpsqlコマンドを使うことができます。

docker-compose ps (dbコンテナ把握)

$ docker-compose ps
         Name                       Command               State                 Ports              
---------------------------------------------------------------------------------------------------
my_project_mailhog_1     MailHog                          Up      1025/tcp, 0.0.0.0:18025->8025/tcp
my_project_memcached_1   docker-entrypoint.sh memcached   Up      11211/tcp                        
my_project_nginx_1       /docker-entrypoint.sh ngin ...   Up      0.0.0.0:10080->80/tcp            
my_project_php-fpm_1     docker-php-entrypoint php-fpm    Up      0.0.0.0:19000->9000/tcp          
my_project_postgres_1    docker-entrypoint.sh postg ...   Up      0.0.0.0:15432->5432/tcp          

postgres っていうコンテナがありますね

繋ぐ

$ docker-compose exec postgres /bin/bash
bash-5.0#

これで使えると思います〜

bash-5.0# psql --version
psql (PostgreSQL) 11.9

ま、環境によってできるできないあると思いますけど基本はこんな形でいけると思います

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