3

I am using a docker-compose.yml file for my django app, and I am trying to do docker-compose run web python manage.py dbshell and drop the table django_admin_log like here.

But this returned
CommandError: You appear not to have the 'psql' program installed or on your path.

How can I do python manage.py dbshell or drop the table django_admin_log?

Here is my docker-compose.yml

storage:
  image: busybox
  volumes:
    - /var/lib/postgresql/data
    - /data
  command: true

db:
  image: postgres
  environment:
     - POSTGRESQL_DB=postgres
     - POSTGRESQL_USER=postgres
     - POSTGRESQL_PASSWORD=password
  volumes_from:
    - storage

web:
  build: .
  environment:
    - DATABASE_HOST=postgres
  command: ./run_web.sh
  ports:
    - "80:80"
  links:
    - db

Thank you

Community
  • 1
  • 1
ksmzn
  • 329
  • 1
  • 2
  • 9

1 Answers1

3

Assuming you are using a Debian or Ubuntu-based image, in your Dockerfile, you just need to add the line:

RUN apt-get update && apt-get -y install postgresql

That will install the psql command for you and allow you to use the dbshell.

Joey Wilhelm
  • 5,729
  • 1
  • 28
  • 42
  • 1
    Thanks. But I don't want to install postgresql on 'web' container because the psql is installed on 'db' container... Is there any good method to connect to 'db' container? – ksmzn Aug 05 '15 at 03:09
  • Actually you do; that is for installing the client, not the server. The web server needs to have the postgresql package in order to get the psql client. – Joey Wilhelm Aug 05 '15 at 03:57
  • Oh, I made a mistake... I was able to use dbshell ! Thanks for your answer. – ksmzn Aug 06 '15 at 02:45
  • 1
    it's possible to install just the client `apt-get install -y postgresql-client` (I'm on Ubuntu 14.04) – Anentropic Oct 03 '15 at 17:39