こちらとこちらを参考に、CentOS7上にCentOS7 DockerコンテナとPostgreSQL 10.5 Dockerコンテナを立ててみました。
CentOS7.4環境へのDockerのインストール
# yum install -y yum-utils device-mapper-persistent-data lvm2
# yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
# yum makecache fast
# yum install docker-ce
# systemctl start docker
# systemctl enable docker
CentOS7イメージの取得
# docker pull centos:centos7
CentOS7上に、CentOS7 Dockerコンテナをtestcontainer という名前で起動する
# docker run --privileged -d --name testcontainer centos:centos7 /sbin/init
コンテナにログイン(shellに接続)
# docker exec -it testcontainer /bin/bash
ログアウト
exit
Postgres10.5 Docker
イメージの取得と確認
# docker pull postgres:10.5
# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
postgres 10.5 084ec18124c8 2 weeks ago
PostgreSQLコンテナの起動
# docker run --name postgres -e POSTGRES_PASSWORD=XXXXX -d postgres:10.5
起動確認
# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
dbc7be879fe8 postgres:10.5 "docker-entrypoint.s…" 12 seconds ago Up 11 seconds
PostgreSQLコンテナへのログイン
# docker exec -it postgres /bin/bash
PostgreSQLへのログイン、データベース一覧の表示
psql -U postgres
postgres=# \l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+----------+----------+------------+------------+-----------------------
postgres | postgres | UTF8 | en_US.utf8 | en_US.utf8 |
template0 | postgres | UTF8 | en_US.utf8 | en_US.utf8 | =c/postgres +
| | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | en_US.utf8 | en_US.utf8 | =c/postgres +
| | | | | postgres=CTc/postgres
(3 rows)
※参考情報
Dockerコマンドまとめ