当前位置:   article > 正文

docker上运行postgresql_posgres docker run

posgres docker run

获取postgresql

docker run postgres --env HTTP_PROXY="socket5://192/168/1/105:1081" -e POSTGRES_PASSWORD=123456
  • 1
docker pull postgres:9.6.17
  • 1

查看image的信息

docker inspect postgres:9.6.17
  • 1

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
  • 1
  • 2
  • 3
  • 4
  • 5

启动一个容器

$ 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
  • 1
  • 2

查看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
  • 1
  • 2
  • 3
  • 4
  • 5

查看postgresql启动日志

docker logs 6526
  • 1

执行一个psql客户端命令

docker exec -it my_pg9.6_2 psql -U postgres
  • 1
docker exec -it my_pg9.6_2 bash
  • 1

数据库准备

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);
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

编辑pg_hba.conf文件

在上面增加一行

local   dev_usr         db1             192.168.33.10           md5
  • 1

遇到的问题

how to see the dockerfile of an image?

how to run a command in a container?
docker exec -it my_pg1

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/AllinToyou/article/detail/464733
推荐阅读
相关标签
  

闽ICP备14008679号