制作 stun/turn 服务 Dockerfile 文件

  • 完整 Dockerfile 文件

    FROM ubuntu:18.04
    
    LABEL maintainer="[email protected]"
    
    # Replace software source - http.
    RUN mv /etc/apt/sources.list /etc/apt/sources.list.bak
    COPY sources.list.http.18.04 /etc/apt/sources.list
    RUN apt-get update
    
    # Install dependent packages
    RUN apt-get install -y \
      gcc \
      libssl-dev \
      make \
      net-tools \
      curl
    	
    # 安装 libevent
    RUN mkdir -p /usr/local/libevent
    ADD libevent-2.1.12.tar.gz /usr/local/libevent
    WORKDIR /usr/local/libevent/libevent-2.1.12
    RUN ./configure && make && make install
    
    # 安装 coturn
    RUN mkdir -p /usr/local/coturn
    ADD coturn-4.5.1.1.tar.gz /usr/local/coturn
    WORKDIR /usr/local/coturn/coturn-4.5.1.1
    RUN ./configure && make && make install
    
    # 拷贝脚本
    WORKDIR /usr/local
    COPY ./turnserver.sh /usr/local/turnserver.sh
    
    ENV TURN_USERNAME lang
    ENV TURN_PASSWORD lang111111
    ENV REALM turn.lang.org
    ENV NAT true
    
    # 暴露容器运行时的 [监听端口] 给外部
    EXPOSE 3478 3478/udp
    
    ENTRYPOINT ["/usr/local/turnserver.sh"]
    
    
  • turnserver.sh

    #!/bin/bash
    set -e
    
    if [ $NAT = "true" -a -z "$EXTERNAL_IP" ]; then
    
      # Try to get public IP
      PUBLIC_IP=$(curl ip.gs) || echo "No public ip found on curl ip.gsc"
      if [ -z "$PUBLIC_IP" ]; then
        PUBLIC_IP=$(curl http://icanhazip.com)
      fi
      if [ -z "$PUBLIC_IP" ]; then
        PUBLIC_IP=$(curl ifconfig.cat)
      fi
      if [ -z "$PUBLIC_IP" ]; then
        echo 'WARN:EXTERNAL IP IS EMPTY!!!'
      fi
    
      #export EXTERNAL_IP="$PUBLIC_IP/$PRIVATE_IP"
      export EXTERNAL_IP="$PUBLIC_IP"
    
    fi
    
    echo 'min-port=49152' > /usr/local/etc/turnserver.conf
    echo 'max-port=65535' >> /usr/local/etc/turnserver.conf
    echo 'fingerprint' >> /usr/local/etc/turnserver.conf
    echo 'lt-cred-mech' >> /usr/local/etc/turnserver.conf
    echo "realm=$REALM" >> /usr/local/etc/turnserver.conf
    echo 'log-file stdout' >> /usr/local/etc/turnserver.conf
    echo "user=$TURN_USERNAME:$TURN_PASSWORD" >> /usr/local/etc/turnserver.conf
    [ $NAT = "true" ] && echo "external-ip=$EXTERNAL_IP" >> /usr/local/etc/turnserver.conf
    
    exec turnserver "$@"
    
    
  • 使用

    #若云服务Docker拉取慢,查看参考解决
    docker build -t coturn:1 .
    # 创建并启动
    docker run -it --name=lang_1 -p 3478:3478 -p 3478:3478/udp coturn:1 #3478端口开启,适合云服务器
    
  • 推荐

    libevent-2.1.12.tar.gz
    coturn-4.5.1.1.tar.gz
    stun/turn 服务搭建详细记录

  • 参考

    Docker——Dockerfile编写实战

    搭建 WebRTC TURN&STUN 服务器

    docker安装stun和turn服务器(打洞服务器)
    国内云服务器(VPS)Docker拉取速度过慢实现加速

你可能感兴趣的:(stun/turn,stun,turn,服务器)