diff --git a/doc/RUN_IN_DOCKER.md b/doc/RUN_IN_DOCKER.md new file mode 100644 index 0000000000000000000000000000000000000000..345aabed52cb30282057ea7f5ba4953a9681d6d8 --- /dev/null +++ b/doc/RUN_IN_DOCKER.md @@ -0,0 +1,175 @@ +# How to run PaddleServing in Docker + +## Requirements + +Docker (GPU version requires nvidia-docker to be installed on the GPU machine) + +## CPU + +### Get docker image + +You can get images in two ways: + +1. Pull image directly + + ```bash + docker pull hub.baidubce.com/ctr/paddleserving:0.1.3 + ``` + +2. Building image based on dockerfile + + Create a new folder and copy [Dockerfile](../tools/Dockerfile) to this folder, and run the following command: + + ```bash + docker build -t hub.baidubce.com/ctr/paddleserving:0.1.3 . + ``` + +### Create container + +```bash +docker run -p 9292:9292 --name test -dit hub.baidubce.com/ctr/paddleserving:0.1.3 +docker exec -it test bash +``` + +The `-p` option is to map the `9292` port of the container to the `9292` port of the host. + +### Install PaddleServing + +In order to make the image smaller, the PaddleServing package is not installed in the image. You can run the following command to install it + +```bash +pip install paddle-serving-server +``` + +### Test example + +Get the trained Boston house price prediction model by the following command: + +```bash +wget --no-check-certificate https://paddle-serving.bj.bcebos.com/uci_housing.tar.gz +tar -xzf uci_housing.tar.gz +``` + +- Test HTTP service + + Running on the Server side (inside the container): + + ```bash + python -m paddle_serving_server.web_serve --model uci_housing_model --thread 10 --port 9292 --name uci &>std.log 2>err.log & + ``` + + Running on the Client side (inside or outside the container): + + ```bash + curl -H "Content-Type:application/json" -X POST -d '{"x": [0.0137, -0.1136, 0.2553, -0.0692, 0.0582, -0.0727, -0.1583, -0.0584, 0.6283, 0.4919, 0.1856, 0.0795, -0.0332], "fetch":["price"]}' http://127.0.0.1:9292/uci/prediction + ``` + +- Test RPC service + + Running on the Server side (inside the container): + + ```bash + python -m paddle_serving_server.serve --model uci_housing_model --thread 10 --port 9292 &>std.log 2>err.log & + ``` + + Running following Python code on the Client side (inside or outside the container, The `paddle-serving-client` package needs to be installed): + + ```bash + from paddle_serving_client import Client + + client = Client() + client.load_client_config("uci_housing_client/serving_client_conf.prototxt") + client.connect(["127.0.0.1:9292"]) + data = [0.0137, -0.1136, 0.2553, -0.0692, 0.0582, -0.0727, + -0.1583, -0.0584, 0.6283, 0.4919, 0.1856, 0.0795, -0.0332] + fetch_map = client.predict(feed={"x": data}, fetch=["price"]) + print(fetch_map) + ``` + + + +## GPU + +The GPU version is basically the same as the CPU version, with only some differences in interface naming (GPU version requires nvidia-docker to be installed on the GPU machine). + +### Get docker image + +You can also get images in two ways: + +1. Pull image directly + + ```bash + nvidia-docker pull hub.baidubce.com/ctr/paddleserving:0.1.3-gpu + ``` + +2. Building image based on dockerfile + + Create a new folder and copy [Dockerfile.gpu](../tools/Dockerfile.gpu) to this folder, and run the following command: + + ```bash + nvidia-docker build -t hub.baidubce.com/ctr/paddleserving:0.1.3-gpu . + ``` + +### Create container + +```bash +nvidia-docker run -p 9292:9292 --name test -dit hub.baidubce.com/ctr/paddleserving:0.1.3-gpu +nvidia-docker exec -it test bash +``` + +The `-p` option is to map the `9292` port of the container to the `9292` port of the host. + +### Install PaddleServing + +In order to make the image smaller, the PaddleServing package is not installed in the image. You can run the following command to install it: + +```bash +pip install paddle-serving-server-gpu +``` + +### Test example + +Get the trained Boston house price prediction model by the following command: + +```bash +wget --no-check-certificate https://paddle-serving.bj.bcebos.com/uci_housing.tar.gz +tar -xzf uci_housing.tar.gz +``` + +- Test HTTP service + + Running on the Server side (inside the container): + + ```bash + python -m paddle_serving_server_gpu.web_serve --model uci_housing_model --thread 10 --port 9292 --name uci + ``` + + Running on the Client side (inside or outside the container): + + ```bash + curl -H "Content-Type:application/json" -X POST -d '{"x": [0.0137, -0.1136, 0.2553, -0.0692, 0.0582, -0.0727, -0.1583, -0.0584, 0.6283, 0.4919, 0.1856, 0.0795, -0.0332], "fetch":["price"]}' http://127.0.0.1:9292/uci/prediction + ``` + +- Test RPC service + + Running on the Server side (inside the container): + + ```bash + python -m paddle_serving_server_gpu.serve --model uci_housing_model --thread 10 --port 9292 + ``` + + Running following Python code on the Client side (inside or outside the container, The `paddle-serving-client` package needs to be installed): + + ```bash + from paddle_serving_client import Client + + client = Client() + client.load_client_config("uci_housing_client/serving_client_conf.prototxt") + client.connect(["127.0.0.1:9292"]) + data = [0.0137, -0.1136, 0.2553, -0.0692, 0.0582, -0.0727, + -0.1583, -0.0584, 0.6283, 0.4919, 0.1856, 0.0795, -0.0332] + fetch_map = client.predict(feed={"x": data}, fetch=["price"]) + print(fetch_map) + ``` + + diff --git a/doc/RUN_IN_DOCKER_CN.md b/doc/RUN_IN_DOCKER_CN.md new file mode 100644 index 0000000000000000000000000000000000000000..7e2f28bdbd73c793faee96def6b625e1bbff2ba9 --- /dev/null +++ b/doc/RUN_IN_DOCKER_CN.md @@ -0,0 +1,171 @@ +# 如何在Docker中运行PaddleServing + +## 环境要求 + +Docker(GPU版本需要在GPU机器上安装nvidia-docker) + +## CPU版本 + +### 获取镜像 + +可以通过两种方式获取镜像。 + +1. 直接拉取镜像 + + ```bash + docker pull hub.baidubce.com/ctr/paddleserving:0.1.3 + ``` + +2. 基于Dockerfile构建镜像 + + 建立新目录,复制[Dockerfile](../tools/Dockerfile)内容到该目录下Dockerfile文件。执行 + + ```bash + docker build -t hub.baidubce.com/ctr/paddleserving:0.1.3 . + ``` + +### 创建容器并进入 + +```bash +docker run -p 9292:9292 --name test -dit hub.baidubce.com/ctr/paddleserving:0.1.3 +docker exec -it test bash +``` + +`-p`选项是为了将容器的`9292`端口映射到宿主机的`9292`端口。 + +### 安装PaddleServing + +为了减小镜像的体积,镜像中没有安装Serving包,要执行下面命令进行安装 + +```bash +pip install paddle-serving-server +``` + +### 测试example + +通过下面命令获取训练好的Boston房价预估模型: + +```bash +wget --no-check-certificate https://paddle-serving.bj.bcebos.com/uci_housing.tar.gz +tar -xzf uci_housing.tar.gz +``` + +- 测试HTTP服务 + + 在Server端(容器内)运行: + + ```bash + python -m paddle_serving_server.web_serve --model uci_housing_model --thread 10 --port 9292 --name uci &>std.log 2>err.log & + ``` + + 在Client端(容器内或容器外)运行: + + ```bash + curl -H "Content-Type:application/json" -X POST -d '{"x": [0.0137, -0.1136, 0.2553, -0.0692, 0.0582, -0.0727, -0.1583, -0.0584, 0.6283, 0.4919, 0.1856, 0.0795, -0.0332], "fetch":["price"]}' http://127.0.0.1:9292/uci/prediction + ``` + +- 测试RPC服务 + + 在Server端(容器内)运行: + + ```bash + python -m paddle_serving_server.serve --model uci_housing_model --thread 10 --port 9292 &>std.log 2>err.log & + ``` + + 在Client端(容器内或容器外,需要安装`paddle-serving-client`包)运行下面Python代码: + + ```python + from paddle_serving_client import Client + + client = Client() + client.load_client_config("uci_housing_client/serving_client_conf.prototxt") + client.connect(["127.0.0.1:9292"]) + data = [0.0137, -0.1136, 0.2553, -0.0692, 0.0582, -0.0727, + -0.1583, -0.0584, 0.6283, 0.4919, 0.1856, 0.0795, -0.0332] + fetch_map = client.predict(feed={"x": data}, fetch=["price"]) + print(fetch_map) + ``` + +## GPU版本 + +GPU版本与CPU版本基本一致,只有部分接口命名的差别(GPU版本需要在GPU机器上安装nvidia-docker)。 + +### 获取镜像 + +可以通过两种方式获取镜像。 + +1. 直接拉取镜像 + + ```bash + nvidia-docker pull hub.baidubce.com/ctr/paddleserving:0.1.3-gpu + ``` + +2. 基于Dockerfile构建镜像 + + 建立新目录,复制[Dockerfile.gpu](../tools/Dockerfile.gpu)内容到该目录下Dockerfile文件。执行 + + ```bash + nvidia-docker build -t hub.baidubce.com/ctr/paddleserving:0.1.3-gpu . + ``` + +### 创建容器并进入 + +```bash +nvidia-docker run -p 9292:9292 --name test -dit hub.baidubce.com/ctr/paddleserving:0.1.3-gpu +nvidia-docker exec -it test bash +``` + +`-p`选项是为了将容器的`9292`端口映射到宿主机的`9292`端口。 + +### 安装PaddleServing + +为了减小镜像的体积,镜像中没有安装Serving包,要执行下面命令进行安装 + +```bash +pip install paddle-serving-server-gpu +``` + +### 测试example + +通过下面命令获取训练好的Boston房价预估模型: + +```bash +wget --no-check-certificate https://paddle-serving.bj.bcebos.com/uci_housing.tar.gz +tar -xzf uci_housing.tar.gz +``` + +- 测试HTTP服务 + + 在Server端(容器内)运行: + + ```bash + python -m paddle_serving_server_gpu.web_serve --model uci_housing_model --thread 10 --port 9292 --name uci + ``` + + 在Client端(容器内或容器外)运行: + + ```bash + curl -H "Content-Type:application/json" -X POST -d '{"x": [0.0137, -0.1136, 0.2553, -0.0692, 0.0582, -0.0727, -0.1583, -0.0584, 0.6283, 0.4919, 0.1856, 0.0795, -0.0332], "fetch":["price"]}' http://127.0.0.1:9292/uci/prediction + ``` + +- 测试RPC服务 + + 在Server端(容器内)运行: + + ```bash + python -m paddle_serving_server_gpu.serve --model uci_housing_model --thread 10 --port 9292 + ``` + + 在Client端(容器内或容器外,需要安装`paddle-serving-client`包)运行下面Python代码: + + ```bash + from paddle_serving_client import Client + + client = Client() + client.load_client_config("uci_housing_client/serving_client_conf.prototxt") + client.connect(["127.0.0.1:9292"]) + data = [0.0137, -0.1136, 0.2553, -0.0692, 0.0582, -0.0727, + -0.1583, -0.0584, 0.6283, 0.4919, 0.1856, 0.0795, -0.0332] + fetch_map = client.predict(feed={"x": data}, fetch=["price"]) + print(fetch_map) + ``` diff --git a/tools/Dockerfile b/tools/Dockerfile index 359dd52c0726e9a421138bf3ecf4d6cff3b2036f..a39ce5bb76e411edeb94766d0c9aae23c6e7e62f 100644 --- a/tools/Dockerfile +++ b/tools/Dockerfile @@ -1,24 +1,8 @@ -FROM centos:centos6.10 -RUN yum -y install wget \ - && wget http://people.centos.org/tru/devtools-2/devtools-2.repo -O /etc/yum.repos.d/devtoolset-2.repo \ - && yum -y install devtoolset-2-gcc devtoolset-2-gcc-c++ devtoolset-2-binutils \ - && source /opt/rh/devtoolset-2/enable \ - && echo "source /opt/rh/devtoolset-2/enable" >> /etc/profile \ - && yum -y install git openssl-devel curl-devel bzip2-devel \ - && wget https://cmake.org/files/v3.5/cmake-3.5.2.tar.gz \ - && tar xvf cmake-3.5.2.tar.gz \ - && cd cmake-3.5.2 \ - && ./bootstrap --prefix=/usr \ - && make \ - && make install \ - && cd .. \ - && rm -r cmake-3.5.2* \ - && wget https://dl.google.com/go/go1.12.12.linux-amd64.tar.gz \ - && tar -xzvf go1.12.12.linux-amd64.tar.gz \ - && mv go /usr/local/go \ - && rm go1.12.12.linux-amd64.tar.gz \ - && echo "export GOROOT=/usr/local/go" >> /root/.bashrc \ - && echo "export GOPATH=$HOME/go" >> /root/.bashrc \ - && echo "export PATH=$PATH:/usr/local/go/bin" >> /root/.bashrc - +FROM centos:7.3.1611 +RUN yum -y install wget && \ + yum -y install epel-release && yum -y install patchelf && \ + yum -y install gcc make python-devel && \ + yum clean all && \ + curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py && \ + python get-pip.py && rm get-pip.py diff --git a/tools/Dockerfile.devel b/tools/Dockerfile.devel new file mode 100644 index 0000000000000000000000000000000000000000..a4b5b5fe48b5c4d5c74d66dc688fa5d594a33266 --- /dev/null +++ b/tools/Dockerfile.devel @@ -0,0 +1,22 @@ +FROM centos:7.3.1611 +RUN yum -y install wget >/dev/null \ + && yum -y install gcc gcc-c++ make glibc-static which >/dev/null \ + && yum -y install git openssl-devel curl-devel bzip2-devel python-devel >/dev/null \ + && wget https://cmake.org/files/v3.2/cmake-3.2.0-Linux-x86_64.tar.gz >/dev/null \ + && tar xzf cmake-3.2.0-Linux-x86_64.tar.gz \ + && mv cmake-3.2.0-Linux-x86_64 /usr/local/cmake3.2.0 \ + && echo 'export PATH=/usr/local/cmake3.2.0/bin:$PATH' >> /root/.bashrc \ + && rm cmake-3.2.0-Linux-x86_64.tar.gz \ + && wget https://dl.google.com/go/go1.14.linux-amd64.tar.gz >/dev/null \ + && tar xzf go1.14.linux-amd64.tar.gz \ + && mv go /usr/local/go \ + && echo 'export GOROOT=/usr/local/go' >> /root/.bashrc \ + && echo 'export PATH=/usr/local/go/bin:$PATH' >> /root/.bashrc \ + && rm go1.14.linux-amd64.tar.gz \ + && yum -y install python-devel sqlite-devel >/dev/null \ + && curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py >/dev/null \ + && python get-pip.py >/dev/null \ + && pip install google protobuf setuptools wheel flask >/dev/null \ + && rm get-pip.py \ + && yum -y install epel-release && yum -y install patchelf \ + && yum clean all diff --git a/tools/Dockerfile.gpu b/tools/Dockerfile.gpu index 5258854691866ab9357a947f42081ae8db6984d7..427ae83bcb805ec70c1e6d575e84234f17e9fb30 100644 --- a/tools/Dockerfile.gpu +++ b/tools/Dockerfile.gpu @@ -1,11 +1,15 @@ -FROM paddlepaddle/paddle_manylinux_devel:cuda9.0_cudnn7 -RUN yum -y install git openssl-devel curl-devel bzip2-devel \ - && wget https://dl.google.com/go/go1.12.12.linux-amd64.tar.gz \ - && tar -xzvf go1.12.12.linux-amd64.tar.gz \ - && rm -rf /usr/local/go \ - && mv go /usr/local/go \ - && rm go1.12.12.linux-amd64.tar.gz \ - && echo "GOROOT=/usr/local/go" >> /root/.bashrc \ - && echo "GOPATH=$HOME/go" >> /root/.bashrc \ - && echo "PATH=$PATH:$GOROOT/bin" >> /root/.bashrc +FROM nvidia/cuda:9.0-cudnn7-runtime-centos7 +RUN yum -y install wget && \ + yum -y install epel-release && yum -y install patchelf && \ + yum -y install gcc make python-devel && \ + yum -y install libSM-1.2.2-2.el7.x86_64 --setopt=protected_multilib=false && \ + yum -y install libXrender-0.9.10-1.el7.x86_64 --setopt=protected_multilib=false && \ + yum -y install libXext-1.3.3-3.el7.x86_64 --setopt=protected_multilib=false && \ + yum clean all && \ + curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py && \ + python get-pip.py && rm get-pip.py && \ + ln -s /usr/local/cuda-9.0/lib64/libcublas.so.9.0 /usr/local/cuda-9.0/lib64/libcublas.so && \ + echo 'export LD_LIBRARY_PATH=/usr/local/cuda/lib64':$LD_LIBRARY_PATH >> /root/.bashrc && \ + ln -s /usr/local/cuda-9.0/targets/x86_64-linux/lib/libcudnn.so.7 /usr/local/cuda-9.0/targets/x86_64-linux/lib/libcudnn.so && \ + echo 'export LD_LIBRARY_PATH=/usr/local/cuda-9.0/targets/x86_64-linux/lib:$LD_LIBRARY_PATH' >> /root/.bashrc