0
0

More than 1 year has passed since last update.

Docker で PostgreSQL を動かす

Last updated at Posted at 2023-05-06

イメージのダウンロード

docker pull postgres:latest

確認

$ docker images
REPOSITORY             TAG           IMAGE ID       CREATED        SIZE

postgres               latest        bf700010ce28   2 days ago     379MB

起動

docker run -d --name=postgres -p 5432:5432 -e POSTGRES_PASSWORD=tiger123 postgres

bash で接続

docker exec -it postgres bash
$ docker exec -it postgres bash
root@4ba8607d4e37:/# cat /etc/os-release 
PRETTY_NAME="Debian GNU/Linux 11 (bullseye)"
NAME="Debian GNU/Linux"
VERSION_ID="11"
VERSION="11 (bullseye)"
VERSION_CODENAME=bullseye
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"
root@4ba8607d4e37:/#

DB に接続

psql -U postgres -h 127.0.0.1
$ psql -U postgres -h 127.0.0.1
Password for user postgres: 
psql (15.2 (Ubuntu 15.2-1))
Type "help" for help.

postgres=# 

ユーザー と データベースを作成

postgres=# create user scott with password 'tiger123';
CREATE ROLE
postgres=# create database city;
CREATE DATABASE
postgres=# alter database city owner to scott;
ALTER DATABASE
postgres=#

作成したユーザーで、作成したデータベースに接続

psql -U scott city -h 127.0.0.1
$ psql -U scott city -h 127.0.0.1
Password for user scott: 
psql (15.2 (Ubuntu 15.2-1))
Type "help" for help.

city=> 
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