Dockerfile 樣板

為了提供 inference 給其他人使用,所以包了包 image 放上 server 給其他人呼叫。這裡記錄一下成果,下次可以直接複製貼上就好 XD


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
FROM tensorflow/tensorflow:2.0.1-gpu-py3

# basic tool
RUN apt-get update \
	&& DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
		zip \
		curl \
		apt-utils \
		locales \
		tzdata \
	&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* \
	&& apt-get autoclean \
	&& apt-get clean

  
# set locale
RUN locale-gen zh_TW.UTF-8
ENV LANG=zh_TW.UTF-8 LANGUAGE=zh_TW:zh LC_ALL=zh_TW.UTF-8


# set timezone
RUN TZ=Asia/Taipei \
	&& ln -snf /usr/share/zoneinfo/$TZ /etc/localtime \
	&& echo $TZ > /etc/timezone \
	&& dpkg-reconfigure -f noninteractive tzdata 


# install inference depend on python packages
RUN apt-get update\
	&& apt-get install -y libsm6 libxext6 libxrender-dev \
	&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* \
	&& apt-get autoclean \
	&& apt-get clean \
	&& pip3 install --upgrade pip \
	&& pip3 install Werkzeug>=0.15.5 \
	   		flask flask-cors requests\
	   		h5py \
	   		numpy  \
	   		opencv-python \
	&& rm -rf ~/.cache/pip

# set working directory && copy data
ARG APP_HOME=/workspace
WORKDIR $APP_HOME
ADD ./workspace $APP_HOME

# port
EXPOSE 9999

# Start the entrypoint command 
CMD python /workspace/inference_server.py

參考資料

  1. yeasy 。使用 Dockerfile 定制镜像 。檢自 Docker —— 从入门到实践 (2020-03-02)。
  2. zxcvbnius (2017-12-22) 。[Day 3] 打造你的Docker containers 。檢自 iT 邦幫忙 (2020-03-02)。