Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

14
  • Thank you very much it works. I tried with this always: docker exect it 40e39bd0329a /bin/bash and then in the container run the psql command, but it always gave me errors. Commented May 8, 2016 at 13:39
  • 2
    To be exact you must be getting psql: FATAL: role "root" does not exist where user that you are connecting as, to the container (root@<SOMETHING>:/#) Commented May 8, 2016 at 15:56
  • 2
    docker-compose exec postgres psql -U project -W project works too if you have a running container (docker-compose up postgres). Commented Nov 28, 2017 at 2:24
  • 4
    After running the above command, I was getting psql: warning: extra command-line argument "project" ignored For me this worked, docker exec -it <container_id> psql -U <username> -W <database_name> Commented Dec 6, 2019 at 3:32
  • 1
    If you define PGPASSWORD environment variable (e.g. in docker-compose.yml), you won't need to type any password. Commented Feb 1, 2024 at 16:43