如果您是第一次阅读该系列文章,建议优先阅读 Docker 部署项目说明及索引
Docker Compose
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
version: '3.9'
services:
postgres:
image: postgres:latest
container_name: postgres
hostname: postgres
restart: unless-stopped
ports:
- "5432:5432"
volumes:
- /docker/postgres/db/data:/var/lib/postgresql/data
environment:
- PGDATA=/var/lib/postgresql/data
- POSTGRES_PASSWORD=your_password
- ALLOW_IP_RANGE=0.0.0.0/0
- TZ=Asia/Shanghai
pgadmin:
image: dpage/pgadmin4:latest
container_name: pgadmin
hostname: pgadmin
restart: unless-stopped
ports:
- "80:80"
volumes:
- /docker/postgres/pgadmin4/data:/var/lib/pgadmin
environment:
- TZ=Asia/Shanghai
- PGADMIN_DEFAULT_PASSWORD=your_password
- PGADMIN_DEFAULT_EMAIL=your_email@example.com
depends_on:
- postgres
networks:
default:
external: true
name: rod
|
NPM 反向代理配置
此处以 https://pgadmin.example.com 为例
如果未部署 NPM,可参考文章:使用 Docker 部署 Nginx Proxy Manager
Details
- Domain Names:
pgadmin.example.com
- Scheme:
http
- Forward Hostname/IP:
127.0.0.1 (如果 NPM 未使用 HOST,则使用容器的 hostname: pgadmin)
- Forward Port:
80
- Cache Assets: ✅
- WebSockets Support: ✅
SSL
- 选择你已经配置好的 SSL Certificate,如
*.example.com, example.com
- Force SSL: ✅
- HTTP/2 Support: ✅
Advanced
1
2
3
4
5
6
7
8
|
location / {
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass $forward_scheme://$server:$port;
}
|
创建用户 & 数据库
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
# 1. 连接 postgres 数据库
psql -U postgres
# 2. 创建 myuser 用户,密码 my_password
create user myuser with password 'my_password';
# 3. 创建 mydb 数据库
create database mydb owner myuser;
# 4. 授权
grant all privileges on database mydb to myuser;
# 5. 退出
\q
|
使用 pgAdmin4
打开链接:https://pgadmin.example.com 登录账号。