tensorflow serving docker
582
official introduce: https://www.tensorflow.org/serving/

Tensorflow Serving - Server
docker run -it -v <client>:/client -p 9000:9000 --name <ts_server> baikangwang/tensorflow_serving_cpu /bin/bash
Tensorflow Serving - Client
# console, desktop program
docker run -it -v <client>:/client --name <ts_client> baikangwang/tensorflow_serving_cpu /bin/bash
# web app
docker run -it -v <client>:/client -p 8080:8080 --name <ts_client> baikangwang/tensorflow_serving_cpu /bin/bash
<client>: it's a placeholder presenting the client code directory
<ts_server>: it's a placeholder presenting the container name being played as SERVER role
<ts_client>: it's a placeholder presenting the container name being played as CLIENT role
9000:9000: the serving service port, the server part is configurable with the evn variable$SERVING_PORT
8080:8080: the client app port which is optional for console, desktop programs, the server part is configurable with the evn variable$CLIENT_PORT
tensorflow_model_server --port=9000 --model_name=<model_name> --model_base_path=/client/<trained_model_path>
console, desktop program
# must use Python2 run the predict program since grpc still dosen't support Python3
python /client/<predict.py> --<args>=... --server=localhost:9000
web app
# must use Python2 run the predict program since grpc still dosen't support Python3
python /client/<web_predict_host.py> --<args>=... --server=localhost:9000 --port=8080
Take the tensorflow serving tutorial, Serving a TensorFlow Model for example, This tutorial introduce how to serving a trained model through bazel build, but in this image the tensorflow serving installed using binary so the code needs a little bit of updates, see baikangwang/MNIST for updated codes.
cd /
git clone [email protected]:baikangwang/MNIST.git
ls -lsa /MNIST
Server
docker run -it -v /MNIST:/client -p 9000:9000 --name ts_server baikangwang/tensorflow_serving_cpu /bin/bash
Client
docker run -it -v /MNIST:/client --name ts_client baikangwang/tensorflow_serving_cpu /bin/bash
Server
tensorflow_model_server --port=9000 --model_name="mnist" --model_base_path="/client/models/"

Client
# Mac
# https://docs.docker.com/docker-for-mac/networking/#known-limitations-use-cases-and-workarounds
python2 /client/mnist_predict.py --num_tests=1000 --server=docker.for.mac.localhost:9000 --data_dir=/client/input_data
# linux
# https://stackoverflow.com/questions/24319662/from-inside-of-a-docker-container-how-do-i-connect-to-the-localhost-of-the-mach
python2 /client/mnist_predict.py --num_tests=1000 --net="host" --server=localhost:9000 --data_dir=/client/input_data

docker pull baikangwang/tensorflow_serving_cpu:latest