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

More than 3 years have passed since last update.

コンテナで使い捨てDBサーバを立てたい

Posted at

覚書です

podman はコンテナ間通信に pod を使う。

podmanの場合
# とりあえず pod を作る
podman pod create --name db

# pauseコンテナ(何もしないコンテナ)が db ポッドの中で起動していることを確認する
podman ps --pod -a

# pod の中でpostgresコンテナを起動する
podman run -d --rm --name some-postgres --pod db -e POSTGRES_PASSWORD=mysecretpassword postgres

# db ポッドの中でpostgresコンテナが起動したことを確認する
podman ps --pod

# psql で接続する
podman run -it --rm --pod db postgres psql -U postgres -h localhost

# psql を終了する
\q

# 後片付け
podman container stop some-postgres
podman pod rm db

docker はコンテナ間通信に network を使う。

dockerの場合
# とりあえず network を作る
docker network create db

# network を指定して postgres コンテナを起動する
docker run -d --rm --net db --name some-postgres -e POSTGRES_PASSWORD=mysecretpassword postgres

# コンテナが指定のネットワークに居ることを確認する
docker container inspect --format="{{json .NetworkSettings.Networks}}" postgres

# psql で接続する
docker run -it --rm --net db postgres psql -h some-postgres -U postgres

# psqlを終了する
\q

# 後片付け
docker container stop some-postgres
docker network rm db
1
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
1
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?