vscode-dev-containers icon indicating copy to clipboard operation
vscode-dev-containers copied to clipboard

unable to run the `psql` command inside a container that includes Postgres

Open adoublef opened this issue 2 years ago • 7 comments

I am not sure if this is deliberate or not, but I cannot run run the pqsl command. I get a bash command not found error.

I have also tried to manually install but would keep getting psql: error: connection to server on socket "/var/run/postgresql/.s.PGSQL.5432" failed as error

I saw a commit here from 2021 of a user claiming to have fixed it and tried to copy the exact same yaml file with no success.

  • VSCode Version: 1.67.2
  • Local OS Version: Win 11
  • Local chip architecture: <x86, arm64, Apple Silicon> arm64
  • Reproduces in: Containers
  • Name of Dev Container Definition with Issue: Go + PostgresDB

Steps to Reproduce:

  1. Connect to container
  2. run the command

adoublef avatar May 22 '22 16:05 adoublef

Try with postgres user. su postgres then psql should work. Also make sure you are executing in database container not go container.

Berkays avatar May 23 '22 14:05 Berkays

What is the database container? I'm using the "Go & PostgreSQL" Dev container and there is no differentiation.

I tried this command in my bash terminal and I got an error saying there is no user. I then checked the users using "cat /etc/passed" and there is no user names postgres

adoublef avatar May 23 '22 16:05 adoublef

It actually creates two seperate containers using docker compose. You should have two containers with names similar to myapp_go and myapp_db

Berkays avatar May 23 '22 16:05 Berkays

Ah I feel stupid thank you. I seem to not be able to access it inside the container even though I can access it via WSL. How would I be able to connect to it inside the container or is that not feasible?

adoublef avatar May 23 '22 17:05 adoublef

I don't use WSL but it should be possible to run docker commands from bash either from powershell or inside the WSL VM itself. You would use regular exec command to ssh into the container such as docker exec –it mycontainer /bin/bash.

Berkays avatar May 23 '22 17:05 Berkays

yh that command I could run inside WSL VM and see my database working. I dont think it be possible to run inside docker commands work inside VSCode devcontainers, or that I haven't managed to get it working (though I realise this is probably expected behaviour).

adoublef avatar May 23 '22 17:05 adoublef

cc @idyll @talk2MeGooseman @jarrodldavis as contributors on definitions containing Postgres

bamurtaugh avatar Jun 01 '22 17:06 bamurtaugh