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でPostgreSQLを起動してみる

Posted at

以前Djangoアプリを作成したので、DjangoアプリからDBにデータを登録できるようにしたい。
ひとまず、DockerでPostgreSQLを起動するところから始める。

PostgreSQLを起動する

まずは、イメージを取得する

docker pull postgres

起動する

docker run --name some-postgres -e POSTGRES_PASSWORD=mypassword -d postgres
  • コンテナにsome-postgresという名前を付ける
  • PostgreSQLのスーパーユーザーパスワードとしてmypasswordを設定
  • 実行するイメージ名はpostgres

以前同じ名前でコンテナを作っていので、以前作っていたコンテナを使いまわす。

docker start some-postgres

コンテナ内からPostgresにアクセス

docker exec -it some-postgres psql -U postgres

プロンプトがpostgres#になっていれば接続できている。

コマンド詳細

  • docker exec コンテナ内でコマンド実行
  • -it ターミナルをインタラクティブモードで実行
  • -U ユーザー名

登録済のテーブルを取得

\dt

振り返り

コンテナ内からのアクセスに加えて、ローカルホストからもアクセス確認したい。
今回、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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?