When I try to run the docker container of clair, there is something wrong with the connection to my pgsql. The docker logs are quoted as follows.
2016-04-05 10:27:47.078096 I | pgsql: running database migrations
2016-04-05 10:27:47.079614 E | pgsql: dial tcp [::1]:5432: getsockopt: connection refused
2016-04-05 10:27:47.079655 C | main: database: could not open database
I have tried several ways and on different machines and the issue still exists.
Did you fill the pgsql setting in your config.yaml file and started with it?
database:
# PostgreSQL Connection string
# http://www.postgresql.org/docs/9.4/static/libpq-connect.html
source:
yes,like this
source: postgresql://mypgsql:1234@localhost:5432/myDB?sslmode=disable
and I run the postgresql container with
sudo docker run --name postgresql -itd --restart always \
--publish 5432:5432 \
--volume /srv/docker/postgresql:/var/lib/postgresql \
--env 'PG_TRUST_LOCALNET=true' \
--env 'PG_PASSWORD=1234' \
--env 'DB_USER=mypgsql' --env 'DB_PASS=1234' \
--env 'DB_NAME=myDB' \
sameersbn/postgresql:9.4-18
I run both successfully on the same machine with DockerCompose and changed source to
postgresql://postgres:password@postgres:5432?sslmode=disable.
Try not specifying a database name.
I use the following to run the Clair container, referring to clair/README.md https://github.com/coreos/clair/blob/master/README.md
$ mkdir $HOME/clair_config
$ curl -L https://raw.githubusercontent.com/coreos/clair/master/config.example.yaml -o $HOME/clair_config/config.yaml
$ $EDITOR $HOME/clair_config/config.yaml # Add the URI for your postgres database
$ docker run -d -p 6060-6061:6060-6061 -v $HOME/clair_config:/config quay.io/coreos/clair -config=/config/config.yaml
And I also tried to run postgresql directly on the host machine, but get the same err as mentioned above.
It is more important how the postgres container is running. Instead of localhost, use the alias "postgres". If you run "docker inspect" on your postgres container, you should see the alias "postgres", and that port 5432 is open for tcp. If you don't see alias "postgres" or port 5432 open for tcp, then you need to use the host or alias and port that is open for you to connect.
And now the logs change to
2016-04-05 13:39:00.291380 I | pgsql: running database migrations
2016-04-05 13:39:00.309188 E | pgsql: dial tcp: lookup postgres on 10.239.27.228:53: server misbehaving
2016-04-05 13:39:00.309353 C | main: database: could not open database
"docker inspect" the postgres container. If you don't see alias "postgres" or port 5432 open for tcp, then you need to use the host or alias and port that is open for connection. The error shows dns can't find the alias. The DockerCompose instructions in the README.md will set up a postgres container for you with the right alias, I recommend it for testing.
Thanks for answering my questions and helping me.
If I check the netstat, I can see the following result.
jun@kube-node-01:~$ sudo netstat -ntlp | grep 5432
tcp 0 0 0.0.0.0:5432 0.0.0.0:* LISTEN 27229/postgres
tcp6 0 0 :::5432 :::* LISTEN 27229/postgres
I will try DockerCompose, but I still wonder if there is any solution for the docker method?
I started PostgreSQL using the command you shared above. Note that I am using docker-machine
.
Now, either with a local Clair binary or using the Docker container, I use the following database source in the config:
host=192.168.99.100 sslmode=disable dbname=postgres user=postgres password=1234 statement_timeout=60000
Host may vary depending on your Docker setup.
When a wrong config file was used, it result in a panic.
Adding some check condition to validate the Unmarshaled configuration
before using it
fixes quay#134
* config: not properly loaded error
When a wrong config file was used, it result in a panic.
Adding some check condition to validate the Unmarshaled configuration
before using it
fixes #134
* check if datasource is set
* move error locally instead of utils/errors
I am facing the same issue
Creating network "go_default" with the default driver
Creating go_postgres_1 ... done
Creating go_app_1 ... done
Attaching to go_postgres_1, go_app_1
postgres_1 | The files belonging to this database system will be owned by user "postgres".
postgres_1 | This user must also own the server process.
postgres_1 |
app_1 | 2018/09/19 21:32:46 dial tcp 127.0.0.1:5432: connect: connection refused
I don't have any other postgres running on 5432.
my docker-compose.yml below
version: '2'
services:
# Application container
build: .
ports:
- "8080:8080"
links:
- postgres
environment:
DEBUG: 'true'
PORT: '8080'
postgres:
image: onjin/alpine-postgres:9.5 #10.5 didn't work out
restart: unless-stopped
ports:
- "5432:5432"
environment:
LC_ALL: C.UTF-8
POSTGRES_USER: test
POSTGRES_PASSWORD: test
POSTGRES_DB: test
Any luck ?
Faced the same problem. Figured out that connection URL to the database should not be localhost
or 127.0.0.1
. It should be URL to your container with the Postgres. So the easiest way to do it is to define something like container_name: clair_postgres
in the docker-compose.yml and use it as a connection string postgresql://postgres:password@clair_postgres:5432?sslmode=disable
EltonSouza, sumeshpremraj, mikeumus, sinetoami, rajgthub, shaddyhm, tteerawat, WIttyJudge, bath, macdonaldezra, and 34 more reacted with thumbs up emoji
mikeumus, bath, danchengash, and KiJo7444 reacted with laugh emoji
mikeumus, sinetoami, shaddyhm, bath, Verkalets, EwenQuim, danchengash, and KiJo7444 reacted with hooray emoji
sinetoami, shaddyhm, WIttyJudge, bath, vasilzhigilei, svirmi, orlandorode97, danchengash, bugrakocabay, didifoprogram, and 4 more reacted with heart emoji
mikeumus, bath, Verkalets, oshanz, orlandorode97, danchengash, bugrakocabay, and KiJo7444 reacted with rocket emoji
All reactions
Faced the same problem. Figured out that connection URL to the database should not be localhost
or 127.0.0.1
. It should be URL to your container with the Postgres. So the easiest way to do it is to define something like container_name: clair_postgres
in the docker-compose.yml and use it as a connection string postgresql://postgres:password@clair_postgres:5432?sslmode=disable
This one worked..after several hours of struggle.