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

http_hooks always connect to localhost on Docker compose #4048

Closed
jimmydrinkscoffee opened this issue May 1, 2024 · 4 comments
Closed

http_hooks always connect to localhost on Docker compose #4048

jimmydrinkscoffee opened this issue May 1, 2024 · 4 comments
Assignees
Labels
API HTTP-API, HTTP-Callback, etc. EnglishNative This issue is conveyed exclusively in English. Won't fix We won't fix it.

Comments

@jimmydrinkscoffee
Copy link

Version: ossrs/srs:5 Docker image

I run SRS locally via docker-compose for testing but the my http_hooks seems not to work.

http_hooks callbacks to my local server listening port 3000. However, there were no requests my server when I started to stream from OBS. And I was still able to do this even when I shutdowned my server.

Screenshot 2024-05-01 at 14 15 33

srs.conf

listen              1935;
max_connections     1000;
daemon              off;
srs_log_tank        console;
vhost __defaultVhost__ {
    http_hooks {
        enabled         on;
        on_publish      http://localhost:3000/live/start;
        on_unpublish    http://localhost:3000/live/end;
        on_play         http://localhost:3000/live/play;
        on_stop         http://localhost:3000/live/stop;
    }
}

compose.yaml

name: dev

services:
    redis:
        container_name: cache
        image: redis
        ports:
            - 6379:6379
        volumes:
            - redis:/data

    rtmp:
        container_name: rtmp
        image: ossrs/srs:5
        volumes:
            - ./srs.conf:/usr/local/srs/conf/srs.conf
        network_mode: host

volumes:
    redis:
        driver: local

I placed the srs.conf file in the same directory of compose.yaml and it's definitely mounted to the container.

$ docker exec -it rtmp /bin/bash    
$ root@orbstack:/usr/local/srs# cat /usr/local/srs/conf/srs.conf
listen              1935;
max_connections     1000;
daemon              off;
srs_log_tank        console;
vhost __defaultVhost__ {
    http_hooks {
        enabled         on;
        on_publish      http://localhost:3000/live/start;
        on_unpublish    http://localhost:3000/live/end;
        on_play         http://localhost:3000/live/play;
        on_stop         http://localhost:3000/live/stop;
    }
}
@winlinvip winlinvip added the EnglishNative This issue is conveyed exclusively in English. label May 1, 2024
@caesar-ibrahimovic
Copy link

I just have solved similar problem, maybe you have the same. Check srs container logs with:
docker container logs <container-id>
There was red error lines like "connection refused" and there was ip 172.x.x.x. I made a conclusion that srs server in docker on windows has another ip sub net and it is trying send callback request to localhost backend server (127.0.0.1). So it can not to connect.
I solved it with hosting backend on local network ip (for example 192.168.1.5) and srs server on VM with Ubuntu (with ip in same subnet 192.168.1.6) . I'm not an expert so maybe there is more simple decision

@jimmydrinkscoffee
Copy link
Author

@caesar-ibrahimovic Very appreciate your response. However, you can see network_mode: host in my srs Docker compose config, which mean srs now is in the same net of my localhost server.

@winlinvip winlinvip changed the title http_hooks doesn't work on Docker compose http_hooks always connect to localhost on Docker compose May 8, 2024
@winlinvip winlinvip self-assigned this May 8, 2024
@winlinvip winlinvip added Won't fix We won't fix it. API HTTP-API, HTTP-Callback, etc. labels May 8, 2024
@winlinvip
Copy link
Member

You should know what localhost means, it's the container itself, not your callback server.

@winlinvip winlinvip closed this as not planned Won't fix, can't repro, duplicate, stale May 8, 2024
@jimmydrinkscoffee
Copy link
Author

jimmydrinkscoffee commented May 8, 2024

I know what localhost is, fortunately and my problem is that even though my callback server isn't there (localhost:3000), I can still stream to the RTMP container. IIRC, it should fail unless the callback API responses with statusCode 2xx. In other words, my RTMP container didn't apply the config at path /usr/local/srs/conf/srs.conf as written in document.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API HTTP-API, HTTP-Callback, etc. EnglishNative This issue is conveyed exclusively in English. Won't fix We won't fix it.
Projects
None yet
Development

No branches or pull requests

3 participants