aws / aws/aws-codebuild-docker-images
Problem to connect postgres instance in local CodeBuild
- Dominant language
- Dockerfile
- Stars
- 1.2k
- Forks
- 971
- Avg merge
- 2h 47m
- Merged PRs (30d)
- 1
Description
I have `buildspec.yml`
```
version: 0.2
phases:
install:
commands:
- docker pull postgres
pre_build:
commands:
- docker run -p 5432:5432 --name sample-postgres -e POSTGRES_PASSWORD=sample -e POSTGRES_USER=sample -e POSTGRES_DB=sample -d postgres >> container.txt
build:
commands:
- sleep 20s
- apt-get install -y telnet iproute2 net-tools
- docker inspect sample-postgres >> container.txt
- ip addr show >> container.txt
- route >> container.txt
- npm i --save pg
- node index.js >> container.txt
post_build:
commands:
- docker rm -f sample-postgres
artifacts:
files:
- container.txt
```
Postgres already created and running.
Postgres connection string:
`postgresql://sample:sample@127.0.0.1:5432/sample`
Can`t connect to postgres in CodeBuild. I got next error:
```
Error: connect ECONNREFUSED 127.0.0.1:5432
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1128:14) {
errno: 'ECONNREFUSED',
code: 'ECONNREFUSED',
syscall: 'connect',
address: '127.0.0.1',
port: 5432
}
```
Docker inspect command of sample-postgres
```
"NetworkSettings": {
"Bridge": "",
"SandboxID": "bf27197fe81dc940a55351c128c87022a963261b9528e5c38f35fad70d1a1c77",
"HairpinMode": false,
"LinkLocalIPv6Address": "",
"LinkLocalIPv6PrefixLen": 0,
"Ports": {
"5432/tcp": [
{
"HostIp": "0.0.0.0",
"HostPort": "5432"
}
]
},
"SandboxKey": "/var/run/docker/netns/bf27197fe81d",
"SecondaryIPAddresses": null,
"SecondaryIPv6Addresses": null,
"EndpointID": "95c48a5070ccd6475292c259bcde4514174f3ff3b042a2d54dcde50b0e80ea3a",
"Gateway": "172.17.0.1",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"IPAddress": "172.17.0.3",
"IPPrefixLen": 16,
"IPv6Gateway": "",
"MacAddress": "02:42:ac:11:00:03",
"Networks": {
"bridge": {
"IPAMConfig": null,
"Links": null,
"Aliases": null,
"NetworkID": "930c686de17cc1c7eed52251f1c860c3564b8b34348fea6c3906d8e9436778a3",
"EndpointID": "95c48a5070ccd6475292c259bcde4514174f3ff3b042a2d54dcde50b0e80ea3a",
"Gateway": "172.17.0.1",
"IPAddress": "172.17.0.3",
"IPPrefixLen": 16,
"IPv6Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"MacAddress": "02:42:ac:11:00:03",
"DriverOpts": null
}
}
}
```
I trying connect with telnet in `buildspec.yml` to database container `sample-postgres` with `IPGateway`, `IPAddress` and got error connection refused
Contributor guide
Assessment
This issue has not been assessed yet.