Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get into psql of a running postgres container?

I created a postgres container using the tutorial on the fig website. I named the container db.

The container is running and my app connects to it fine. I tried to run the command fig run db psql with the db container running and got the error:

psql: could not connect to server: No such file or directory     Is the server running locally and accepting     connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"? 

How can I get into the psql interface in the running db container?

like image 525
sargas Avatar asked Dec 28 '14 03:12

sargas


People also ask

How do I get into PostgreSQL terminal?

Getting a PostgreSQL command prompt You can get a command shell in Windows by running cmd.exe. The CSEP544 shell launcher script will also open a shell for you. Type psql -U postgres at the prompt, and hit Enter. Here, postgres represents the username of the database superuser.


1 Answers

fig will create a docker container with a different name than the one used in the fig.yml file.

I got it working by finding the container name with docker ps and looking at the NAMES column.

Then running the psql command in the running container with docker exec -ti NAME_OF_CONTAINER psql -U YOUR_POSTGRES_USERNAME

Important Note:

  • docker exec runs the psqlcommand on a running container
  • docker run will start a new container.

Update

fig is now called docker-compose

like image 185
sargas Avatar answered Sep 17 '22 19:09

sargas