Search code examples
dockerrtsp

Connection to tcp://localhost:8554?timeout=0 failed: Cannot assign requested address


I have two docker containers. The first one I run using this command:

docker run -d --network onprem_network --name rtsp_simple_server --rm -t -e RTSP_PROTOCOLS=tcp -p 8554:8554 aler9/rtsp-simple-server

The second docker is created from these files: Dockerfile:

FROM python:slim-buster
ENV PYTHONUNBUFFERED 1
ENV PYTHONDONTWRITEBYTECODE 1
WORKDIR /code
COPY rtsp_streaming.py /code/
COPY ConsoleCapture_clipped.mp4 /code
RUN apt update && apt-get update && apt install ffmpeg -y # && apt-get install ffmpeg libsm6 libxext6  -y
CMD ["python", "/code/rtsp_streaming.py"]

rtsp_streaming.py:

import os
os.system("ffmpeg -re -stream_loop 0 -i ConsoleCapture_clipped.mp4 -c copy -f rtsp rtsp://localhost:8554/mystream")

I run the second docker container like so:

docker run --network onprem_network -v ${data_folder}:/code/Philips_MR --name rtsp_streaming -d rtsp_streaming

docker ps -a yields:

CONTAINER ID   IMAGE                      COMMAND                  CREATED          STATUS                      PORTS                    NAMES
48ea091b870d   rtsp_streaming             "python /code/rtsp_s…"   18 minutes ago   Exited (0) 18 minutes ago                            rtsp_streaming
5376e070f89f   aler9/rtsp-simple-server   "/rtsp-simple-server"    19 minutes ago   Up 19 minutes               0.0.0.0:8554->8554/tcp   rtsp_simple_server

The second container exits quickly with this error:

Connection to tcp://localhost:8554?timeout=0 failed: Cannot assign requested address

Any suggestions how to fix this?


Solution

  • You should use rtsp_simple_server:8554 instead of localhost.

    Since in the container called rtsp_streaming, localhost means rtsp_streaming and in rtsp_simple_server, localhost means rtsp_simple_server`. So you should use the container's name.