本文共 5552 字,大约阅读时间需要 18 分钟。
没啥事在写一篇,制作docker镜像,主要是把上一篇讯飞服务器的代码和环境打包到docker中。
之前还不知道怎么在docker中安装Python的第三方库,试过之后原来很简单,只要基于Python环境,在利用RUN命令pip install就行了。
最基本的制作,Dockerfile内容:
FROM python:3.5.6WORKDIR /serverCOPY ./dc_asr_client /server/dc_asr_client/COPY ./simplified_asr_server_rpc.py /server/RUN pip3 install websocketRUN pip3 install websocket-clientRUN pip3 install grpcio RUN pip3 install googleRUN pip3 install protobufEXPOSE 8015CMD python3 simplified_asr_server_rpc.py
逐行解释下dockerfile文件的内容:
基于Python3.5.6的镜像
工作目录:server
把本地的dc_asr_client 文件夹里的内容拷贝到镜像的/server/dc_asr_client/目录下,主要拷贝格式
把本地的服务器端文件simplified_asr_server_rpc.py 拷贝到镜像的/server目录下
安装websocket库
安装websocket-client库
安装grpcio
安装google
安装protobuf
暴露端口8015
最后运行主文件simplified_asr_server_rpc.py
docker镜像构建命令:
sudo docker build -t xunfei/dc_asr_rpc:1.2 .
构建过程:
Sending build context to Docker daemon 45.06 kBStep 1/11 : FROM python:3.5.6 ---> 537c3cbb1df0Step 2/11 : WORKDIR /server ---> Using cache ---> f6b91680e15aStep 3/11 : COPY ./dc_asr_client /server/dc_asr_client/ ---> Using cache ---> 97b15708d8f9Step 4/11 : COPY ./simplified_asr_server_rpc.py /server/ ---> Using cache ---> fec075f46a87Step 5/11 : RUN pip3 install websocket ---> Running in 77ea63213356Collecting websocket Downloading https://files.pythonhosted.org/packages/f2/6d/a60d620ea575c885510c574909d2e3ed62129b121fa2df00ca1c81024c87/websocket-0.2.1.tar.gz (195kB)Collecting gevent (from websocket) Downloading https://files.pythonhosted.org/packages/95/d2/f2f454b00fde1608f6f4889c8cc3e12b5000f26cd5c3e11b5427c7781de9/gevent-1.4.0-cp35-cp35m-manylinux1_x86_64.whl (5.4MB)Collecting greenlet (from websocket) Downloading https://files.pythonhosted.org/packages/2e/65/27f35497cc0102a792390d056e793e064da95fc9eae45d75ae0ba49c0a0d/greenlet-0.4.15-cp35-cp35m-manylinux1_x86_64.whl (41kB)Building wheels for collected packages: websocket Building wheel for websocket (setup.py): started Building wheel for websocket (setup.py): finished with status 'done' Stored in directory: /root/.cache/pip/wheels/35/f7/5c/9e8243838269ea93f05295708519a6e183fa6b515d9ce3b636Successfully built websocketInstalling collected packages: greenlet, gevent, websocketSuccessfully installed gevent-1.4.0 greenlet-0.4.15 websocket-0.2.1 ---> e404af6e273eRemoving intermediate container 77ea63213356Step 6/11 : RUN pip3 install websocket-client ---> Running in 332a24c558e9Collecting websocket-client Downloading https://files.pythonhosted.org/packages/26/2d/f749a5c82f6192d77ed061a38e02001afcba55fe8477336d26a950ab17ce/websocket_client-0.54.0-py2.py3-none-any.whl (200kB)Collecting six (from websocket-client) Downloading https://files.pythonhosted.org/packages/73/fb/00a976f728d0d1fecfe898238ce23f502a721c0ac0ecfedb80e0d88c64e9/six-1.12.0-py2.py3-none-any.whlInstalling collected packages: six, websocket-clientSuccessfully installed six-1.12.0 websocket-client-0.54.0 ---> 0c90b6397a51Removing intermediate container 332a24c558e9Step 7/11 : RUN pip3 install grpcio ---> Running in 5b5d42874687Collecting grpcio Downloading https://files.pythonhosted.org/packages/ea/72/dbdce5ba0eb2ee22069430f1c18c2fef22b4f6ffbf188ab2d416695f3992/grpcio-1.18.0-cp35-cp35m-manylinux1_x86_64.whl (10.6MB)Requirement already satisfied: six>=1.5.2 in /usr/local/lib/python3.5/site-packages (from grpcio) (1.12.0)Installing collected packages: grpcioSuccessfully installed grpcio-1.18.0 ---> 72de782d159cRemoving intermediate container 5b5d42874687Step 8/11 : RUN pip3 install google ---> Running in 3d249172c282Collecting google Downloading https://files.pythonhosted.org/packages/c8/b1/887e715b39ea7d413a06565713c5ea0e3132156bd6fc2d8b165cee3e559c/google-2.0.1.tar.gzCollecting beautifulsoup4 (from google) Downloading https://files.pythonhosted.org/packages/1d/5d/3260694a59df0ec52f8b4883f5d23b130bc237602a1411fa670eae12351e/beautifulsoup4-4.7.1-py3-none-any.whl (94kB)Collecting soupsieve>=1.2 (from beautifulsoup4->google) Downloading https://files.pythonhosted.org/packages/bf/b3/2473abf05c4950c6a829ed5dcbc40d8b56d4351d15d6939c8ffb7c6b1a14/soupsieve-1.7.3-py2.py3-none-any.whlBuilding wheels for collected packages: google Building wheel for google (setup.py): started Building wheel for google (setup.py): finished with status 'done' Stored in directory: /root/.cache/pip/wheels/b3/6d/94/ad59f018e26ad1987116a8eda758a4dd4285fcb0b4daf7c50dSuccessfully built googleInstalling collected packages: soupsieve, beautifulsoup4, googleSuccessfully installed beautifulsoup4-4.7.1 google-2.0.1 soupsieve-1.7.3 ---> 62a60e8dc6ccRemoving intermediate container 3d249172c282Step 9/11 : RUN pip3 install protobuf ---> Running in 7861ca5f5fa6Collecting protobuf Downloading https://files.pythonhosted.org/packages/bf/d4/db7296a1407cad69f043537ba1e05afab3646451a066ead7a314d8714388/protobuf-3.6.1-cp35-cp35m-manylinux1_x86_64.whl (1.1MB)Requirement already satisfied: setuptools in /usr/local/lib/python3.5/site-packages (from protobuf) (40.6.3)Requirement already satisfied: six>=1.9 in /usr/local/lib/python3.5/site-packages (from protobuf) (1.12.0)Installing collected packages: protobufSuccessfully installed protobuf-3.6.1 ---> 2916480aa098Removing intermediate container 7861ca5f5fa6Step 10/11 : EXPOSE 8015 ---> Running in bf69db641b15 ---> 9dc822d78beeRemoving intermediate container bf69db641b15Step 11/11 : CMD python3 simplified_asr_server_rpc.py ---> Running in fe9b00f657be ---> 0e9075075beaRemoving intermediate container fe9b00f657beSuccessfully built 0e9075075bea
docker容器运行命令:
docker run -itd --net host --name xunfei-asr-1.0.0 --restart unless-stopped xunfei/dc_asr_rpc:1.2
转载地址:http://jdxws.baihongyu.com/