Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to connect to Centrifugo on localhost:8000 (only works on container IP) #2708

Closed
alexc-hollywood opened this issue Sep 15, 2020 · 1 comment

Comments

@alexc-hollywood
Copy link

Description:

Adding container image for Centrifugo exposes the service on the container IP, but not localhost.

Within docker-compose.yml:

### CENTRIFUGO ###################################################
# https://centrifugal.github.io/centrifugo/server/configuration/#configuration-ways
    centrifugo:
      container_name: centrifugo
      image: centrifugo/centrifugo:latest
      restart: always
      environment:
        - CENTRIFUGO_ADDRESS=0.0.0.0
        - CENTRIFUGO_ENGINE=memory
        - CENTRIFUGO_ADMIN=true
        - CENTRIFUGO_TOKEN_HMAC_SECRET_KEY=secret
        - CENTRIFUGO_ADMIN_PASSWORD=password
        - CENTRIFUGO_ADMIN_SECRET=secret
        - CENTRIFUGO_API_KEY=centrifugo_spi_client
        - CENTRIFUGO_V3_USE_OFFSET=true
        - CENTRIFUGO_LOG_LEVEL=debug
        - CENTRIFUGO_CLIENT_CHANNEL_LIMIT=128
        - CENTRIFUGO_CHANNEL_MAX_LENGTH=255
        - CENTRIFUGO_CLIENT_REQUEST_MAX_SIZE=65536
        - CENTRIFUGO_CLIENT_QUEUE_MAX_SIZE=10485760
        - CENTRIFUGO_CLIENT_ANONYMOUS=FALSE
        - CENTRIFUGO_SOCKJS_HEARTBEAT_DELAY=25
        - CENTRIFUGO_WEBSOCKET_COMPRESSION=FALSE
        - CENTRIFUGO_GOMAXPROCS=0
        - CENTRIFUGO_WEBSOCKET_HANDLER_PREFIX="/connection/websocket"
        - CENTRIFUGO_SOCKJS_HANDLER_PREFIX="/connection/sockjs"
        - CENTRIFUGO_API_HANDLER_PREFIX="/api"
        - CENTRIFUGO_PROMETHEUS_HANDLER_PREFIX="/metrics"
        - CENTRIFUGO_HEALTH_HANDLER_PREFIX="/health"
      ports:
        - "8569:8000"
      command: centrifugo --admin --health
      networks:
        - backend

Launch:

docker-compose up -d --force-recreate centrifugo
Recreating centrifugo ... 
Recreating centrifugo ... done

docker ps
CONTAINER ID        IMAGE                          COMMAND                  CREATED             STATUS              PORTS                    NAMES
db068814eff6        centrifugo/centrifugo:latest   "centrifugo --admin …"   12 minutes ago      Up 12 minutes       0.0.0.0:8569->8000/tcp   centrifugo

Trying to connect:

curl -X GET http://127.0.0.1:8000
curl: (7) Failed to connect to 127.0.0.1 port 8000: Connection refused

However, check the internal private container IP and it works:

curl -X GET http://172.22.0.2:8000
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
    <title>Centrifugo admin panel</title>
    <link rel="shortcut icon" href="favicon.png" type="image/x-icon" />
    <link href="https://use.fontawesome.com/releases/v5.6.3/css/all.css" rel="stylesheet" />
<link rel="shortcut icon" href="favicon.png"><link href="styles.css?2784449a7d3509c03bf4" rel="stylesheet"></head>

<body>
    <div id="app"></div>
<script type="text/javascript" src="bundle.js?2784449a7d3509c03bf4"></script></body>

</html>

Expected Behavior:

Able to successfully connect to http://localhost:8000 in browser.

Context information:

Output of git rev-parse HEAD

ade6f6b1a79fbe87f971d1021a9e5e1ee57a0fd3

Output of docker version

Client: Docker Engine - Community
 Version:           19.03.12
 API version:       1.40
 Go version:        go1.13.10
 Git commit:        48a66213fe
 Built:             Mon Jun 22 15:45:36 2020
 OS/Arch:           linux/amd64
 Experimental:      false

Server: Docker Engine - Community
 Engine:
  Version:          19.03.12
  API version:      1.40 (minimum version 1.12)
  Go version:       go1.13.10
  Git commit:       48a66213fe
  Built:            Mon Jun 22 15:44:07 2020
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.2.13
  GitCommit:        7ad184331fa3e55e52b890ea95e65ba581ae3429
 runc:
  Version:          1.0.0-rc10
  GitCommit:        dc9208a3303feef5b3839f4323d9beb36df0a9dd
 docker-init:
  Version:          0.18.0
  GitCommit:        fec3683

Output of docker-compose version

docker-compose version 1.17.1, build unknown
docker-py version: 2.5.1
CPython version: 2.7.17
OpenSSL version: OpenSSL 1.1.1g  21 Apr 2020

System info: Mac, Windows or Linux. Include which disto/version

Ubuntu 18 Bionic

Steps to reproduce the issue:

  1. Add above config to docker-compose.yml
  2. Run docker-compose up -d --force-recreate centrifugo
  3. Visit http://localhost:8000
  4. Get container private IP, visit http://container-ip:8000

Stacktrace & Additional info:

docker-compose logs centrifugo
Attaching to centrifugo
centrifugo             | {"level":"info","version":"2.6.2","runtime":"go1.14.7","pid":1,"engine":"Memory","gomaxprocs":4,"time":"2020-09-15T01:32:06Z","message":"starting Centrifugo"}
centrifugo             | {"level":"info","path":"/centrifugo/config.json","time":"2020-09-15T01:32:06Z","message":"using config file"}
centrifugo             | {"level":"warn","time":"2020-09-15T01:32:06Z","message":"config file not found"}
centrifugo             | {"level":"info","time":"2020-09-15T01:32:06Z","message":"serving websocket, SockJS, API, admin, health endpoints on 0.0.0.0:8000"}

@alexc-hollywood
Copy link
Author

Closing this. Fixed by changing the port relay, which is in the format docker-host : container host

Changed to:

      ports:
        - "8000:8000"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant