docker 安装及启动 postgresql 及navicat 连接

2021/8/4 19:06:28

本文主要是介绍docker 安装及启动 postgresql 及navicat 连接,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

docker-compose.yml

version: '2.1'
services:
  vincent-db:
    image: daocloud.io/library/postgres:10
    volumes:
      - ./data/postgres:/var/lib/postgresql/data
      - ./init-db:/docker-entrypoint-initdb.d
    environment:
        POSTGRES_USER: vincent
        POSTGRES_PASSWORD: 521314
        POSTGRES_DB: vincent
    ports:
      - 5433:5433
    expose:
      - 5432
    restart: always

docker-compose up 

 

docker pa -s # 查看容器

haha@haha-W330-H30:~$ docker ps -a
CONTAINER ID        IMAGE                             COMMAND                  CREATED             STATUS                      PORTS                                     NAMES
5fc7956bc3f3        daocloud.io/library/postgres:10   "docker-entrypoint.s…"   44 minutes ago      Up 44 minutes               5432/tcp, 0.0.0.0:5433->5433/tcp          local_compose_vincent-db_1
7a89d9827cb9        postgres:10.4                     "docker-entrypoint.s…"   2 months ago        Up 4 days                   0.0.0.0:5432->5432/tcp                    koji-psql
6d0f04351875        dockercloud/haproxy               "/sbin/tini -- docke…"   2 months ago        Exited (255) 2 months ago   443/tcp, 1936/tcp, 0.0.0.0:9003->80/tcp   docker-compose-0_lb_1
11f8b08a5476        redis                             "docker-entrypoint.s…"   2 months ago        Exited (255) 2 months ago   6379/tcp                                  docker-compose-0_redis_1
0875cccee8de        dockercloud/hello-world           "/bin/sh -c /run.sh"     2 months ago        Exited (255) 2 months ago   0.0.0.0:9002->80/tcp                      docker-compose-0_web_1
14f139e21223        containrrr/watchtower             "/watchtower nginx r…"   2 months ago        Up 4 days                   8080/tcp, 0.0.0.0:9001->80/tcp            watchtower
0f9a04f29e5b        nginx                             "/docker-entrypoint.…"   2 months ago        Exited (255) 2 months ago   0.0.0.0:6063->80/tcp                      web3
514dd1730e0e        nginx                             "/docker-entrypoint.…"   2 months ago        Exited (255) 2 months ago   0.0.0.0:6062->80/tcp                      web2
25083d85008d        nginx                             "/docker-entrypoint.…"   2 months ago        Exited (255) 2 months ago   0.0.0.0:6061->80/tcp                      web1
 

 

 

docker进入容器

docker exec -it <容器id>  bash

# 进入 pgsql 容器

  docker exec -it 5fc7956bc3f3 bash

haha@haha-W330-H30:~$ docker exec -it 5fc7956bc3f3 bash
root@5fc7956bc3f3:/# psql -U vincent 
psql (10.16 (Debian 10.16-1.pgdg90+1))
Type "help" for help.

vincent=# \l
                               List of databases
   Name    |  Owner  | Encoding |  Collate   |   Ctype    |  Access privileges  
-----------+---------+----------+------------+------------+---------------------
 postgres  | vincent | UTF8     | en_US.utf8 | en_US.utf8 | template0 | vincent | UTF8     | en_US.utf8 | en_US.utf8 | =c/vincent         +
           |         |          |            |            | vincent=CTc/vincent
 template1 | vincent | UTF8     | en_US.utf8 | en_US.utf8 | =c/vincent         +
           |         |          |            |            | vincent=CTc/vincent
 vincent   | vincent | UTF8     | en_US.utf8 | en_US.utf8 | 
(5 rows)

vincent=# 

 

查看容器的ip

docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' <容器id>
haha@haha-W330-H30:~$ docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' 5fc7956bc3f3
172.23.0.2

 

NAVICAT 连接数据库

 



这篇关于docker 安装及启动 postgresql 及navicat 连接的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程