SRS Dockerfile 模板

以下是一个 SRS Dockerfile 模板,它将 SRS 的默认端口修改为:

功能原端口修改后的端口
HTTP API (信令)19851338
播放/页面80801337
WebRTC (UDP)80001336
RTMP19351335

📁 文件结构示例:

.
├── Dockerfile
└── srs.conf

🔧 srs.conf 示例配置文件

listen              1335;  # RTMP

http_api {
    enabled         on;
    listen          1338;  # HTTP API
    crossdomain     on;
}

http_server {
    enabled         on;
    listen          1337;  # 播放页面
    dir             ./objs/nginx/html;
}

rtc_server {
    enabled         on;
    listen          1336;  # WebRTC UDP 端口
    candidate       host.docker.internal;
}

🐳 Dockerfile 示例

FROM ossrs/srs:5

# 写入自定义配置文件
RUN mkdir -p /usr/local/srs/conf && \
cat > /usr/local/srs/conf/srs.conf <<EOF
listen              1335;  # RTMP

http_api {
    enabled         on;
    listen          1338;  # HTTP API
    crossdomain     on;
}

http_server {
    enabled         on;
    listen          1337;  # 播放页面
    dir             ./objs/nginx/html;
}

rtc_server {
    enabled         on;
    listen          1336;  # WebRTC UDP 端口
    candidate       host.docker.internal;
}
EOF

# 添加 WebRTC 播放页面
RUN mkdir -p /usr/local/srs/objs/nginx/html && \
cat > /usr/local/srs/objs/nginx/html/webrtc-player.html <<EOF
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>WebRTC 播放器</title>
  <style>
    body { background: #111; color: #fff; text-align: center; font-family: sans-serif; }
    video { width: 80%; margin-top: 20px; background: #000; }
    input { width: 60%; padding: 10px; font-size: 16px; }
    button { padding: 10px 20px; font-size: 16px; }
  </style>
</head>
<body>
  <h1>📺 WebRTC 播放端</h1>
  <input id="url" type="text" value="webrtc://localhost/live/livestream">
  <button onclick="startPlay()">▶️ 播放</button>
  <br><video id="video" autoplay playsinline controls muted></video>

  <script>
    async function startPlay() {
      const playUrl = document.getElementById("url").value;
      const pc = new RTCPeerConnection();
      const video = document.getElementById("video");

      pc.ontrack = event => {
        video.srcObject = event.streams[0];
      };

      const res = await fetch("http://" + location.hostname + ":1338/rtc/v1/play", {
        method: "POST",
        body: JSON.stringify({
          api: "/rtc/v1/play",
          streamurl: playUrl,
          clientip: null,
          sdp: (await pc.createOffer()).sdp
        })
      });
      const data = await res.json();

      await pc.setLocalDescription({ type: "offer", sdp: data.sdp });
      await pc.setRemoteDescription({ type: "answer", sdp: data.sdp });

      console.log("✅ 播放连接建立成功");
    }
  </script>
</body>
</html>
EOF

# 启动 SRS
CMD ["./objs/srs", "-c", "/usr/local/srs/conf/srs.conf"]


🧪 构建和运行容器

docker build --network=host -t my-srs .
docker run --name srs-mod -d --network=host \  # 使用 host 网络以避免端口映射
  my-srs

⚠️ --network=host 只适用于 Linux。若使用 macOS/Windows,你需要 -p 映射端口(虽然你希望不使用它)。


💬 补充说明

  • candidate 设置为 host.docker.internal 可用于 WebRTC 在宿主机中运行浏览器时的 NAT 反射;
  • 如果你是在 Linux 且使用 --network=host,这些端口会直接监听在宿主机上,无需 -p

No Comments

Send Comment Edit Comment


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
Previous
Next