1

I am a little bit confused. I am launching daphne locally this way: daphne common.asgi:channel_layer --port 8338 and everything is "ok" with it. When I use curl -v 127.0.0.1:8338 get the following output

* Rebuilt URL to: 127.0.0.1:8338/
*   Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to 127.0.0.1 (127.0.0.1) port 8338 (#0)
> GET / HTTP/1.1
> Host: 127.0.0.1:8338
> User-Agent: curl/7.51.0
> Accept: */*

But when I try to launch docker container with port allocation, it doesn't argue that 8338 port is already used:

    docker run \
    -tid \
    -p 8338:8338 \
    -v $(PWD):/app \
    --network matryoshka_net \
    --hostname matryoshka_daphne \
    --name matryoshka_daphne \
    matryoshka_daphne

Running above code is "ok" with daphne already launched. So it seems to me that ports were not allocated properly.

What am I missing?

So that produces next problem, that I can't redirect signals to websockets to my docker container by nginx. Because there is nothing on port 8338 (when only container launched). Here is nginx.conf:

server {
    listen 127.0.0.1;

    gzip on;
    gzip_types text/plain application/json text/css application/x-javascript text/javascript application/javascript;

    location / {
        proxy_set_header Host $host;
        proxy_read_timeout 20s;
        client_max_body_size 10m;
        proxy_pass http://127.0.0.1:8000;
    }

    location /ws/ {
        proxy_pass http://127.0.0.1:8338;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
    }
}
Snobby
  • 1,067
  • 3
  • 18
  • 38
  • Can you make sure that the daphne instance outside Docker is binding to the same interface? Does it bind to 0.0.0.0 or directly to 127.0.0.1? If you are running nginx locally on the same host, you can also redirect `/ws/` directly to the container's IP address. By default, those look like 172.17.0.X. – JulioHM May 10 '17 at 15:01
  • So, I understood, I am running daphne outside container on host 127.0.0.1, and container argues on ports only if the process was launched on 0.0.0.0. I still have difficulties with understanding these host mapping, but realised why I am launching container succesfully. – Snobby May 10 '17 at 15:29
  • Docker containers have 2 interfaces: the loopback interface (127.0.0.1) and a another (usually 172.17.0.x/16) that is connected to the host. You need to use 0.0.0.0. – Ricardo Branco May 10 '17 at 16:02

1 Answers1

1

I understand that you have nginx in the same machine when you run docker. In proxy_pass you should point to docker IP, which should be 0.0.0.0, so the line in the conf should look like:

proxy_pass http://0.0.0.0:8338;

It should be the same for both locations: location / and location /ws/ because you are running daphne on port 8338.

Please take a look at my example conf (it is using daphne and gunicorn) however can be change to use only daphne.

pplonski
  • 5,023
  • 1
  • 30
  • 34