Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker: Empty response from server

Tags:

node.js

docker

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 :)

like image 693
Halil Irmak Avatar asked Sep 26 '18 18:09

Halil Irmak


3 Answers

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.

like image 60
Halil Irmak Avatar answered Nov 20 '22 14:11

Halil Irmak


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
like image 41
Dev Sareno Avatar answered Nov 20 '22 16:11

Dev Sareno


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

like image 4
temirbek Avatar answered Nov 20 '22 16:11

temirbek