1. clone配置文件到本地服务器
git clone https://github.com/BetterVoice/freeswitch-container.git
相关Dockerfile如下:
# Jenkins. FROM ubuntu:16.04 MAINTAINER Thomas Quintana <thomas@bettervoice.com> # Enable the Ubuntu multiverse repository. RUN echo "deb http://us.archive.ubuntu.com/ubuntu/ trusty multiverse" >> /etc/apt/source.list RUN echo "deb-src http://us.archive.ubuntu.com/ubuntu/ trusty multiverse">> /etc/apt/source.list RUN echo "deb http://us.archive.ubuntu.com/ubuntu/ trusty-updates multiverse" >> /etc/apt/source.list RUN echo "deb-src http://us.archive.ubuntu.com/ubuntu/ trusty-updates multiverse" >> /etc/apt/source.list # Enable videolan stable repository. RUN apt-get update && apt-get install -y software-properties-common RUN add-apt-repository ppa:videolan/stable-daily # Install Dependencies. # missing in 16.04 libmyodbc RUN apt-get update && apt-get install -y autoconf automake bison build-essential fail2ban gawk git-core groff groff-base erlang-dev libasound2-dev libavcodec-dev libavutil-dev libavformat-dev libav-tools libavresample-dev libswscale-dev liba52-0.7.4-dev libssl-dev libdb-dev libexpat1-dev libcurl4-openssl-dev libgdbm-dev libgnutls-dev libjpeg-dev libmp3lame-dev libncurses5 libncurses5-dev libperl-dev libogg-dev libsnmp-dev libtiff5-dev libtool libvorbis-dev libx11-dev libzrtpcpp-dev make portaudio19-dev python-dev snmp snmpd subversion unixodbc-dev uuid-dev zlib1g-dev libsqlite3-dev libpcre3-dev libspeex-dev libspeexdsp-dev libldns-dev libedit-dev libladspa-ocaml-dev libmemcached-dev libmp4v2-dev libpq-dev libvlc-dev libv8-dev liblua5.2-dev libyaml-dev libpython-dev odbc-postgresql sendmail unixodbc wget yasm libldap2-dev # Use Gawk. RUN update-alternatives --set awk /usr/bin/gawk # Install source code dependencies. ADD build/install-deps.sh /root/install-deps.sh WORKDIR /root RUN chmod +x install-deps.sh RUN ./install-deps.sh RUN rm install-deps.sh # Configure Fail2ban ADD conf/freeswitch.conf /etc/fail2ban/filter.d/freeswitch.conf ADD conf/freeswitch-dos.conf /etc/fail2ban/filter.d/freeswitch-dos.conf ADD conf/jail.local /etc/fail2ban/jail.local RUN touch /var/log/auth.log # Download FreeSWITCH. WORKDIR /usr/src ENV GIT_SSL_NO_VERIFY=1 #RUN git clone https://freeswitch.org/stash/scm/fs/freeswitch.git -b v1.6 RUN git clone https://github.com/signalwire/freeswitch.git -b v1.6 # Bootstrap the build. WORKDIR freeswitch RUN ./bootstrap.sh # Enable the desired modules. ADD build/modules.conf /usr/src/freeswitch/modules.conf # Build FreeSWITCH. RUN ./configure --enable-core-pgsql-support RUN make RUN make install RUN make uhd-sounds-install RUN make uhd-moh-install # RUN make samples # Post install configuration. ADD sysv/init /etc/init.d/freeswitch RUN chmod +x /etc/init.d/freeswitch RUN update-rc.d -f freeswitch defaults ADD sysv/default /etc/default/freeswitch ADD build/bashrc /root/.bashrc ADD conf/fs_sync /bin/fs_sync # Add the freeswitch user. RUN adduser --gecos "FreeSWITCH Voice Platform" --no-create-home --disabled-login --disabled-password --system --ingroup daemon --home /usr/local/freeswitch freeswitch RUN chown -R freeswitch:daemon /usr/local/freeswitch # Add confile file ADD build/lib/* /usr/lib/ RUN ln /usr/lib/x86_64-linux-gnu/libpcre32.so.3.13.2 /usr/lib/libpcre.so.1 RUN ln /usr/lib/x86_64-linux-gnu/libedit.so.2.0.53 /usr/lib/libedit.so.0 RUN ln /usr/lib/libssl.so.1.0.0 /usr/lib/libssl.so.10 RUN ln /usr/lib/libcrypto.so.1.0.0 /usr/lib/libcrypto.so.10 ADD build/token.txt /usr/local/freeswitch/bin/ ADD build/robot.conf /usr/local/freeswitch/bin/ ADD build/alitoken_time.cfg /usr/local/freeswitch/bin/ ADD build/alitoken /usr/local/freeswitch/bin/ ADD build/mod_vmd.so /usr/local/freeswitch/mod/ ADD conf/* /usr/local/freeswitch/conf/ RUN chmod +x /usr/local/freeswitch/bin/alitoken # Create the log file. RUN touch /usr/local/freeswitch/log/freeswitch.log RUN chown freeswitch:daemon /usr/local/freeswitch/log/freeswitch.log # Open the container up to the world. EXPOSE 5060/tcp 5060/udp 5080/tcp 5080/udp EXPOSE 5066/tcp 7443/tcp EXPOSE 8021/tcp EXPOSE 64535-65535/udp # Start the container. CMD service snmpd start && service freeswitch start && tail -f /usr/local/freeswitch/log/freeswitch.log
2. 执行构建命令
docker build -t freeswitch .
3. 启动container
CID=$(sudo docker run --name freeswitch -p 5060:5060/tcp -p 5060:5060/udp -p 5080:5080/tcp -p 5080:5080/udp -p 8021:8021/tcp -p 7443:7443/tcp -v /usr/local/freeswitch-container/conf:/usr/local/freeswitch/conf freeswitch)
参数解读:
-d:后台运行;
-p:端口映射 上述左边5060为宿机端口,右边5060为容器内部端口;
-v:文件挂载 指定宿机目录映射到容器内部的目录(上述就是把宿机/usr/local/freeswitch-container/conf的地址映射到容器内部的/usr/local/freeswitch/conf目录里面去)
执行下面命令代替启动命令中加参数 -p 60535-65535:60535-65535/udp
CIP=$(sudo docker inspect --format='{{.NetworkSettings.IPAddress}}' $CID) sudo iptables -A DOCKER -t nat -p udp -m udp ! -i docker0 --dport 60535:65535 -j DNAT --to-destination $CIP:60535-65535 sudo iptables -A DOCKER -p udp -m udp -d $CIP/32 ! -i docker0 -o docker0 --dport 60535:65535 -j ACCEPT sudo iptables -A POSTROUTING -t nat -p udp -m udp -s $CIP/32 -d $CIP/32 --dport 60535:65535 -j MASQUERADE
启动container并进入container shell:
docker run -it freeswitch /bin/bash
进入container:
docker exec -it freeswitch /bin/bash
查找容器:
docker ps -a
获取容器长ID:
docker inspect -f '{{.ID}}' freeswitch
拷贝本地文件到容器:
docker cp 你的文件路径 容器长ID:docker容器路径
拷贝容器文件到本地:
docker cp <containerId>:/file/path/within/container /host/path/target