如何在Docker容器中显示PostgreSQL数据库?

时间:2017-08-30 18:02:11

标签: python django postgresql python-3.x docker

我在Docker容器中同时拥有Django项目和PotgreSQL数据库。我的问题是如何显示我的数据库?我正在尝试docker exec -ti myproject_django_1 /bin/bashdocker exec -ti myproject_db_1 /bin/bash,但在这两种情况下,由于psqlpsql: 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]

1 个答案:

答案 0 :(得分:0)

您的方法是正确的,只需在进入容器时更改用户:

docker exec -ti myproject_db_1 /bin/bash

su - postgres
psql