获取postgresql
docker run postgres --env HTTP_PROXY="socket5://192/168/1/105:1081" -e POSTGRES_PASSWORD=123456
docker pull postgres:9.6.17
查看image的信息
docker inspect postgres:9.6.17
What is different of Config and ContainerConfig of docker inspect?
查看网络
docker network ls
NETWORK ID NAME DRIVER SCOPE
52fad4374751 bridge bridge local
cab444d41edc host host local
92aa63d09f76 none null local
启动一个容器
$ docker run --name my_pg9.6_2 -e POSTGRES_PASSWORD=xxx -v /mnt/pgdata1/:/var/lib/postgresql/data/ --network c2c79ef52c7e -p 15432:5432 -d postgres:9.6.17
65262a17ae01e9c8346b4d00524a272488808c69a513498d5296459926d06969
查看docker进程是否正常
$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
65262a17ae01 postgres:9.6.17 "docker-entrypoint.s…" 6 seconds ago Up 3 seconds 0.0.0.0:15432->5432/tcp my_pg9.6_2
54b8fa0923eb postgres "docker-entrypoint.s…" 22 hours ago Exited (1) 22 hours ago focused_kapitsa
33c38803545b postgres "docker-entrypoint.s…" 22 hours ago Exited (1) 22 hours ago affectionate_hellman
查看postgresql启动日志
docker logs 6526
执行一个psql客户端命令
docker exec -it my_pg9.6_2 psql -U postgres
docker exec -it my_pg9.6_2 bash
数据库准备
postgres=# create role dev;
postgres=# create user dev_usr;
postgres=# grant dev to dev_usr;
postgres=# create database db1;
postgres=# \c db1;
db1=# create schema business;
db1=# grant all privileges on schema business to dev;
db1=# alter database db1 set search_path to 'business,public';
db1=# alter database db1 owner to dev;
db1=# alter user dev_usr encrypted password 'zjhello';
db1=# create table business.aaa (aa int);
编辑pg_hba.conf文件
在上面增加一行
local dev_usr db1 192.168.33.10 md5
遇到的问题
how to see the dockerfile of an image?
how to run a command in a container?
docker exec -it my_pg1