我有一个包含python
、nginx
、postgres
和pgadmin
服务的docker-compose
文件:
services:
postgres:
image: postgres:9.6
env_file: .env
volumes:
- postgres_data:/var/lib/postgresql/data
ports:
- "5431:5431"
pgadmin:
image: dpage/pgadmin4
links:
- postgres
depends_on:
- postgres
environment:
PGADMIN_DEFAULT_EMAIL: admin@admin.com
PGADMIN_DEFAULT_PASSWORD: pwdpwd
volumes:
- pgadmin:/root/.pgadmin
ports:
- "5050:80"
backend:
build:
context: ./foobar # This refs a Dockerfile with Python and Django requirements
command: ["/wait-for-it.sh", "postgres:5431", "--", "/gunicorn.sh"]
volumes:
- staticfiles_root:/foobar/static
depends_on:
- postgres
nginx:
build:
context: ./foobar/docker/nginx
volumes:
- staticfiles_root:/foobar/static
depends_on:
- backend
ports:
- "0.0.0.0:80:80"
volumes:
postgres_data:
staticfiles_root:
pgadmin:
当我运行
docker-compose up
并访问localhost:5050
时,我会看到pgadmin
界面。当我尝试在那里创建一个新的服务器,使用localhost
或0.0.0.0
作为主机名和5431
作为端口时,我会收到一个错误“无法连接到服务器”。如果我删除这些内容,而是在“服务”字段中输入postgres
,我会收到错误“找不到服务“postgres”的定义”。我如何使用pgadmin
连接到数据库?