Ysqlsh: could not connect to server: Connection refused

ysqlsh: could not connect to server: Connection refused
Is the server running on host “localhost” (127.0.0.1) and accepting
TCP/IP connections on port 5433?
could not connect to server: Cannot assign requested address
Is the server running on host “localhost” (::1) and accepting
TCP/IP connections on port 5433?

i’m getting this error while trying to run yugabyte in my local using docker , anyone help me to resolve this

Hi,

do you have port-forwarding enabled for your container? I use this command to start a fresh docker-yugabyte container (note the -p flags):

docker run -d --name yugabyte -p7200:7200 -p7000:7000 -p9000:9000 -p5433:5433 -p9042:9042 yugabytedb/yugabyte:latest bin/yugabyted start --daemon=false --ui=false

Hi Sebastian,
I’m using the same command
docker run -d --name yugabyte -p7200:7200 -p7000:7000 -p9000:9000 -p5433:5433 -p9042:9042 yugabytedb/yugabyte:latest bin/yugabyted start --daemon=false --ui=false

this worked for me yesterday. after updating my docker am facing this error.

C:>docker run -d --name yugabyte -p7200:7200 -p7000:7000 -p9000:9000 -p5433:5433 -p9042:9042 yugabytedb/yugabyte:latest bin/yugabyted start --daemon=false --ui=false
016d21df244918a5160a1cb02a903de8d049205fc2ad6f14333d5e5b3959e717

C:>docker exec -it yugabyte /home/yugabyte/bin/ysqlsh --echo-queries
ysqlsh: could not connect to server: Connection refused
Is the server running on host “localhost” (127.0.0.1) and accepting
TCP/IP connections on port 5433?
could not connect to server: Cannot assign requested address
Is the server running on host “localhost” (::1) and accepting
TCP/IP connections on port 5433?

I sometimes had the problem, that yugabyted would not start if I had terminated the container without gracefully shutting it down. The reason was that there still was a “yugabyted.pid” and the yugabyted server therefore didn’t even start. Maybe that helps…

you can do something like

docker exec -it yugabyte /bin/bash

and start the yugabyted server yourself from the shell (run /home/yugabyte/bin/yugabyted start --daemon=false --ui=false) to see if there’s some error output

[root@b92fa99f3e8d yugabyte]# /home/yugabyte/bin/yugabyted start --daemon=false --ui=false
yugabyted is already running!

i’m getting the above but still unable to run query from bash
[root@b92fa99f3e8d yugabyte]# /home/yugabyte/bin/ysqlsh --echo-queries
ysqlsh: could not connect to server: Connection refused
Is the server running on host “localhost” (127.0.0.1) and accepting
TCP/IP connections on port 5433?
could not connect to server: Cannot assign requested address
Is the server running on host “localhost” (::1) and accepting
TCP/IP connections on port 5433?

there you have it! That’s the problem. You have a “yugabyte.pid” file laying around and therefore the yugabyted process thinks that there’s already an instance running.

I’d recommend you use a docker volume, to map the data folder of yugabyte to your host filesystem and then you can always easily remove the .pid file if this happens.

add
“-v [AN ABSOLUTE PATH TO AN EXISTING FOLDER ON YOUR HOST]:/home/yugabyte/var”
to your docker command

then you will get all important the files yugabyte creates in your local folder and then you can easily delete “[AN ABSOLUTE PATH TO AN EXISTING FOLDER ON YOUR HOST]/data/yugabyted.pid”

Also, I had to connect to the container itself, by pointing to the interface of the container, ex: 172.17.0.2 (look in the docker logs yugabyte and discover it by issuing docker inspect yugabyte).
Which means:

docker exec -it yugabyte /home/yugabyte/bin/ysqlsh --echo-queries -h 172.17.0.2 -p 5433
ysqlsh (11.2-YB-2.17.2.0-b0)
Type "help" for help.

yugabyte=#

Now is working

I use:

docker exec -it yugabyte bash -c 'ysqlsh --echo-queries -h $(hostname) -p 5433'

to avoid a docker inspect

1 Like