-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
83 lines (76 loc) · 2.99 KB
/
Dockerfile
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
FROM alpine:3.7
# Based on https://github.com/tatsushid/docker-alpine-py3-tensorflow-jupyter/blob/master/Dockerfile
# Changes:
# - Bumping versions of Bazel and Tensorflow
# - Add -Xmx to the Java params when building Bazel
# - Disable TF_GENERATE_BACKTRACE and TF_GENERATE_STACKTRACE
ENV JAVA_HOME /usr/lib/jvm/java-1.8-openjdk
ENV LOCAL_RESOURCES 2048,.5,1.0
ENV BAZEL_VERSION 0.10.0
RUN apk add --no-cache python3 python3-tkinter py3-numpy py3-numpy-f2py freetype libpng libjpeg-turbo imagemagick graphviz git
RUN apk add --no-cache --virtual=.build-deps \
bash \
cmake \
curl \
freetype-dev \
g++ \
libjpeg-turbo-dev \
libpng-dev \
linux-headers \
make \
musl-dev \
openblas-dev \
openjdk8 \
patch \
perl \
python3-dev \
py-numpy-dev \
rsync \
sed \
swig \
zip \
&& cd /tmp \
&& pip3 install --no-cache-dir wheel \
&& $(cd /usr/bin && ln -s python3 python)
# Bazel download
RUN curl -SLO https://github.com/bazelbuild/bazel/releases/download/${BAZEL_VERSION}/bazel-${BAZEL_VERSION}-dist.zip \
&& mkdir bazel-${BAZEL_VERSION} \
&& unzip -qd bazel-${BAZEL_VERSION} bazel-${BAZEL_VERSION}-dist.zip
# Bazel install
RUN cd bazel-${BAZEL_VERSION} \
&& sed -i -e 's/-classpath/-J-Xmx8192m -J-Xms128m -classpath/g' scripts/bootstrap/compile.sh \
&& bash compile.sh \
&& cp -p output/bazel /usr/bin/
# Download Tensorflow
ENV TENSORFLOW_VERSION 1.7.0
RUN cd /tmp \
&& curl -SL https://github.com/tensorflow/tensorflow/archive/v${TENSORFLOW_VERSION}.tar.gz \
| tar xzf -
# Build Tensorflow
RUN cd /tmp/tensorflow-${TENSORFLOW_VERSION} \
&& : musl-libc does not have "secure_getenv" function \
&& sed -i -e '/JEMALLOC_HAVE_SECURE_GETENV/d' third_party/jemalloc.BUILD \
&& sed -i -e '/define TF_GENERATE_BACKTRACE/d' tensorflow/core/platform/default/stacktrace.h \
&& sed -i -e '/define TF_GENERATE_STACKTRACE/d' tensorflow/core/platform/stacktrace_handler.cc \
&& PYTHON_BIN_PATH=/usr/bin/python \
PYTHON_LIB_PATH=/usr/lib/python3.6/site-packages \
CC_OPT_FLAGS="-march=native" \
TF_NEED_JEMALLOC=1 \
TF_NEED_GCP=0 \
TF_NEED_HDFS=0 \
TF_NEED_S3=0 \
TF_ENABLE_XLA=0 \
TF_NEED_GDR=0 \
TF_NEED_VERBS=0 \
TF_NEED_OPENCL=0 \
TF_NEED_CUDA=0 \
TF_NEED_MPI=0 \
bash configure
RUN cd /tmp/tensorflow-${TENSORFLOW_VERSION} \
&& bazel build --jobs 6 -c opt --local_resources ${LOCAL_RESOURCES} //tensorflow/tools/pip_package:build_pip_package
RUN cd /tmp/tensorflow-${TENSORFLOW_VERSION} \
&& ./bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg
RUN cp /tmp/tensorflow_pkg/tensorflow-${TENSORFLOW_VERSION}-cp36-cp36m-linux_x86_64.whl /root
# Make sure it's built properly
RUN pip3 install --no-cache-dir /root/tensorflow-${TENSORFLOW_VERSION}-cp36-cp36m-linux_x86_64.whl \
&& python3 -c 'import tensorflow'