拉取镜像
docker pull postgres:10
docker-compose.yml
version: "3"
services:
db:
image: "postgres:10"
container_name: "my_postgres"
ports:
- "54320:5432"
volumes:
- my_dbdata:/Users/yutou/postgresql/data
- /data:/Users/yutou/postgresql/bin
environment:
- POSTGRES_PASSWORD=password123
volumes:
my_dbdata:
挂载目录:
- ./bin:/pg/bin,
宿主机:容器
, 如果没有, 都可以创建的. ```yaml version: ‘3’
- ./bin:/pg/bin,
services: postgres: container_name: “my_postgres” image: “postgres:10” environment: POSTGRES_USER: ${POSTGRES_USER:-postgres} POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-password123} PGDATA: /data/postgres volumes:
- ./postgres:/data/postgres
ports:
- "54320:5432"
networks:
- postgres
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:
- pgadmin:/root/.pgadmin
ports:
- "${PGADMIN_PORT:-5050}:80"
networks:
- postgres
restart: unless-stopped
networks: postgres: driver: bridge
volumes: postgres: pgadmin:
感觉上面的挂载目录不太对, 正确的是应该挂载镜像的 `var` 目录:
```yaml
./postgres_data:/var/lib/postgresql/data
运行
# 运行
docker-compose up -d
# 查看镜像是否成功
docker ps
dbeaver 设置
注意用户名是: postgres