Reputation: 1399
I am having trouble to connect docker container, server returns empty response however the configuration seems to be correct.
When i use docker-compose up command everything seems fine and working however i am getting empty response from server.
I double checked the port mappings however i couldnt notice anything.
Here is the compose file
version: '3'
services:
authapi:
build:
dockerfile: ./docker/Dockerfile.dev
context: .
restart: always
volumes:
- .:/usr/src/auth
- /usr/src/auth/node_modules
environment:
FBAPPID: ${FBAPPID}
FBAPPSECRET: ${FBAPPSECRET}
GOOGLEAPPID: ${GOOGLEAPPID}
GOOGLEAPPSECRET: ${GOOGLEAPPSECRET}
GITHUBAPPID: ${GITHUBAPPID}
GITHUBAPPSECRET: ${GITHUBAPPSECRET}
ports:
- ${PORT}:${PORT}
command:
- sh
- -c
- sleep 20 && npm run start:dev
depends_on:
- psql
psql:
image: postgres:10-alpine
ports:
- 5432:5432
environment:
POSTGRES_USER: ${PG_USER}
POSTGRES_PASSWORD: ${PG_PASSWORD}
POSTGRES_DB: ${PG_DB}
volumes:
- ./pg-data:/var/lib/postgresql/data
Dockerfile
FROM node:10-alpine
WORKDIR /usr/src/auth
COPY ./package.json .
RUN npm install
COPY . .
EXPOSE 9091
CMD ["npm", "run", "start:prod"]
docker port response
9091/tcp -> 0.0.0.0:9091
docker ps response
CONTAINER ID IMAGE COMMAND
CREATED STATUS PORTS NAMES
cecbf815523e authservice_authapi "sh -c 'sleep 20 && …" 15
minutes ago Up 15 minutes 0.0.0.0:9091->9091/tcp
authservice_authapi_1
4e5c5f312703 postgres:10-alpine "docker-entrypoint.s…" 15
minutes ago Up 15 minutes 0.0.0.0:5432->5432/tcp
authservice_psql_1
here is docker network
NETWORK ID NAME DRIVER SCOPE
3bb18805e2b1 authservice_default bridge local
f7fb02e95fc3 bridge bridge local
815dccd6c8b8 host host local
12ca56c3c08d none null local
authservice_default inspect response
[
{
"Name": "authservice_default",
"Id": "3bb18805e2b129342ce255017c88b8d72717f050419503d81042f5319b5f5009",
"Created": "2018-09-26T18:24:01.3773204Z",
"Scope": "local",
"Driver": "bridge",
"EnableIPv6": false,
"IPAM": {
"Driver": "default",
"Options": null,
"Config": [
{
"Subnet": "172.18.0.0/16",
"Gateway": "172.18.0.1"
}
]
},
"Internal": false,
"Attachable": true,
"Ingress": false,
"ConfigFrom": {
"Network": ""
},
"ConfigOnly": false,
"Containers": {
"4e5c5f3127036fe300ec2917fd6023d00ca8d3c4e28b583107c2deabc6fd2dda": {
"Name": "authservice_psql_1",
"EndpointID": "461b8164f174d436a4a039ff9ff494cac3bc5f6f96c1b8d0619928c8dafb6652",
"MacAddress": "02:42:ac:12:00:02",
"IPv4Address": "172.18.0.2/16",
"IPv6Address": ""
},
"cecbf815523e4028c2b9cb1d74104ef61cc8fb8947624c9df8f035193842a9b0": {
"Name": "authservice_authapi_1",
"EndpointID": "af30a79b70d675002f12bd61ca8aed2d8d5f036bd99c10fa7a205cf3e21ae19b",
"MacAddress": "02:42:ac:12:00:03",
"IPv4Address": "172.18.0.3/16",
"IPv6Address": ""
}
},
"Options": {},
"Labels": {
"com.docker.compose.network": "default",
"com.docker.compose.project": "authservice",
"com.docker.compose.version": "1.22.0"
}
}
]
logs of containers
[nodemon] starting `node ./src/babel.start.js`
{"level":30,"time":1537987440400,"msg":"Server listening at http://127.0.0.1:9091","pid":63,"hostname":"cecbf815523e","v":1}
|-----------------------------Start-----------------------------|
| |
| Server started on http://127.0.0.1:9091
| |
|---------------------------------------------------------------|
|-----------------------------CPU INFO--------------------------|
| |
| Cpu 0: Intel(R) Core(TM) i5-5257U CPU @ 2.70GHz => speed 2697
| Cpu 1: Intel(R) Core(TM) i5-5257U CPU @ 2.70GHz => speed 2697
| |
|----------------------TOTAL MEMORY ----------------------------|
| |
|========================> 2 GB
| |
|-----------------------FREE MEMORY-----------------------------|
| |
|========================> 155.5 MB
| |
|------------------------PLATFORM-------------------------------|
| |
|========================> linux v4.9.93-linuxkit-aufs x64
| |
|---------------------------------------------------------------|
|------------------------IFACE IP-------------------------------|
| |
|========================> 172.18.0.3
| |
|---------------------------------------------------------------|
i dont add here postgress one because application has nothing to do with postgress now.
Everything seems fine from my perspective, am i missing something ? Huge thanks already now for those who tries to help :)
Upvotes: 28
Views: 32956
Reputation: 11
In my case using node:alpine
on dockerfile
was the problem for me, just changing the image to the Node.js
It turns out the alpine version is not official. The drawback though is image-size.
I was able to make my API talk normally to my DB passing the DB's container name on the Postgres host variable, and setting up a network in the docker-compose file.
By the way, my setup was Nestjs, TypeORM, Postgres and Docker.
Upvotes: 1
Reputation: 696
I encountered the same problem using Dockerize GatsbyJS. As Halil Irmak's comment, the issue was resolved by binding the application to 0.0.0.0
. On my case
yarn develop -H 0.0.0.0 -p 8000
Upvotes: 3
Reputation: 49
I encountered this problem and solved it.
The problem is that, although my HOST config is right, I still receive ERR_EMPTY_RESPONSE.
Here's my solution:
The first time you start strapi with docker is really slow. So if you have done everything right, then just wait for the page to start. I waited 23 mins at the first time...
If you are wondering whether it's slow or something you did is wrong, you can try this:
find strapi container id: run docker ps
enter the container: run docker exec -it <container id> bash
(if you can enter the container, maybe you have done everything right.)
check if the port is open: run echo > /dev/tcp/127.0.0.1/1337
When it says 'bash: /dev/tcp/127.0.0.1/1337: Connection refused', it means your strapi service is not ready yet.
if the command returns nothing, then strapi service is ready. Check http://127.0.0.1:1337/admin , you will find what you want.
Upvotes: 1
Reputation: 1452
I had same problem but binding to 0.0.0.0 didn't help, this answer helped me saying that container port should be higher than 1024 because of privileges. I was using default port 80, after exposing 8080 and binding 0.0.0.0 it now started to work
Upvotes: 4
Reputation: 1399
I have solved the problem by binding the application to 0.0.0.0 and everything started to work.
I hope it would be useful anybody who are looking for solution for this kind of issue.
Upvotes: 70