docker - 使用postgresql

在docker中使用postgresql数据库

 

搜索镜像

# docker search postgres

 

拉取镜像

# docker pull postgres

 

查看镜像

# docker image ls

REPOSITORY TAG IMAGE ID CREATED SIZE

postgres latest 67ebc8a2f066 2 weeks ago 237MB

 

建立文件夹

# mkdir /data/pgsql-data

 

启动容器

# docker run --name pglatest -v /data/pgsql-data/:/var/lib/postgresql/data/ -p 54321:5432 -d postgres:latest

 

查看容器

# docker container ls

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES

0ad90d457159 postgres:latest "docker-entrypoint.s…" 9 seconds ago Up 8 seconds 0.0.0.0:54321->5432/tcp pglatest

 

连接数据库

1. 通过运行docker容器,exec进入psql

# docker exec -it pglatest psql -U postgres -d postgres

psql (10.5 (Debian 10.5-1.pgdg90+1))

Type "help" for help.

postgres=#

2. 通过客户端连接数据库

# psql -U mytest -d mytest -h 127.0.0.1 -p 54321

psql (11beta3, server 10.5 (Debian 10.5-1.pgdg90+1))

Type "help" for help.

mytest=#

3. 其他机器连接数据库

# psql -U mytest -d mytest -h dbtest03bc -p 54321

psql (10.3, server 10.5 (Debian 10.5-1.pgdg90+1))

Type "help" for help.

mytest=#

 

查看文件

# cd /data/pgsql-data/

# ls

PG_VERSION global pg_dynshmem pg_ident.conf pg_multixact pg_replslot pg_snapshots pg_stat_tmp pg_tblspc pg_wal postgresql.auto.conf postmaster.opts

base pg_commit_ts pg_hba.conf pg_logical pg_notify pg_serial pg_stat pg_subtrans pg_twophase pg_xact postgresql.conf postmaster.pid

 

阅读更多

没有更多推荐了,返回首页