我在Docker容器中同时拥有Django项目和PotgreSQL数据库。我的问题是如何显示我的数据库?我正在尝试docker exec -ti myproject_django_1 /bin/bash
和docker exec -ti myproject_db_1 /bin/bash
,但在这两种情况下,由于psql
或psql: FATAL: role "root" does not exist
bash: psql: command not found
搬运工-compose.yml:
version: '3'
services:
redis:
image: redis:alpine
db:
image: postgres
django:
build: .
command: python3 manage.py runserver 0.0.0.0:8000
volumes:
- .:/code
ports:
- "8000:8000"
depends_on:
- db
links:
- redis
angular:
build: frontend
ports:
- "4200:4200"
depends_on:
- django
SOLUTION:
docker exec -it [DB_CONTAINER_ID] psql -U [USERNAME]
答案 0 :(得分:0)
您的方法是正确的,只需在进入容器时更改用户:
docker exec -ti myproject_db_1 /bin/bash
su - postgres
psql