拉取镜像

  1. docker pull postgres:10

docker-compose.yml

  1. version: "3"
  2. services:
  3. db:
  4. image: "postgres:10"
  5. container_name: "my_postgres"
  6. ports:
  7. - "54320:5432"
  8. volumes:
  9. - my_dbdata:/Users/yutou/postgresql/data
  10. - /data:/Users/yutou/postgresql/bin
  11. environment:
  12. - POSTGRES_PASSWORD=password123
  13. volumes:
  14. my_dbdata:

挂载目录:

    • ./bin:/pg/bin, 宿主机:容器 , 如果没有, 都可以创建的. ```yaml version: ‘3’

services: postgres: container_name: “my_postgres” image: “postgres:10” environment: POSTGRES_USER: ${POSTGRES_USER:-postgres} POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-password123} PGDATA: /data/postgres volumes:

  1. - ./postgres:/data/postgres
  2. ports:
  3. - "54320:5432"
  4. networks:
  5. - postgres
  6. restart: unless-stopped

web 管理页面

pgadmin: container_name: pgadmin_container image: dpage/pgadmin4 environment: PGADMIN_DEFAULT_EMAIL: ${PGADMIN_DEFAULT_EMAIL:-pgadmin4@pgadmin.org} PGADMIN_DEFAULT_PASSWORD: ${PGADMIN_DEFAULT_PASSWORD:-admin} volumes:

  1. - pgadmin:/root/.pgadmin
  2. ports:
  3. - "${PGADMIN_PORT:-5050}:80"
  4. networks:
  5. - postgres
  6. restart: unless-stopped

networks: postgres: driver: bridge

volumes: postgres: pgadmin:

  1. 感觉上面的挂载目录不太对, 正确的是应该挂载镜像的 `var` 目录:
  2. ```yaml
  3. ./postgres_data:/var/lib/postgresql/data

运行

  1. # 运行
  2. docker-compose up -d
  3. # 查看镜像是否成功
  4. docker ps

dbeaver 设置

注意用户名是: postgres

image.png