Skip to content

Instantly share code, notes, and snippets.

@RainJayTsai
Created April 15, 2019 01:56
Show Gist options
  • Save RainJayTsai/e2dc2371324cca8e04b95165b4655068 to your computer and use it in GitHub Desktop.
Save RainJayTsai/e2dc2371324cca8e04b95165b4655068 to your computer and use it in GitHub Desktop.
build tensorflow in docker the image is python:3.6 ( debian )
FROM python:3.6
# install bazel
# check the bazel version what you want to build tensroflw and change the VERSION
# https://www.tensorflow.org/install/source#linux
ARG BAZEL_VERSION 0.15.0
ARG TENSORFLOW_VERSION 1.12.0
RUN apt-get update; apt-get install openjdk-8-jdk
RUN set -ex && wget https://github.com/bazelbuild/bazel/releases/download/${BAZEL_VERSION}/bazel-${BAZEL_VERSION}-installer-linux-x86_64.sh \
&& chmod +x bazel-${BAZEL_VERSION}-installer-linux-x86_64.sh ./bazel-${BAZEL_VERSION}-installer-linux-x86_64.sh \
&& ./bazel-${BAZEL_VERSION}-installer-linux-x86_64.sh && bazel
# install tensorflow dependency
RUN apt-get install --no-install-reocmmends python3-dev python3-pip
RUN pip install -U --user pip six numpy wheel setuptools mock \
&& pip install -U --user keras_applications==1.0.6 --no-deps \
&& pip install -U --user keras_preprocessing==1.0.5 --no-deps
# download tensorflow source code from github
WORKDIR /usr/src/build/
RUN git clone https://github.com/tensorflow/tensorflow.git \
&& cd tensorflow \
&& git checkout $TENSORFLOW_VERSION
WORKDIR /usr/src/build/tensorflow
RUN export \
PYTHON_BIN_PATH=/usr/local/bin/python3.6 \
PYTHON_LIB_PATH=/usr/local/lib/python3.6/site-packages/ \
TF_NEED_JEMALLOC=0 \
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 \
&& ./configure \
&& bazel build --config=opt //tensorflow/tools/pip_package:build_pip_package \
&& ./bazel-bin/tensorflow/tools/pip_package/build_pip_package /mnt
@RainJayTsai
Copy link
Author

build tensorflow

ref1
ref2
ref3
ref4

wget 'https://github.com/bazelbuild/bazel/releases/download/0.15.0/bazel-0.15.0-installer-linux-x86_64.sh'
chmod +x bazel-0.15.0-installer-linux-x86_64.sh ./bazel-0.15.0-installer-linux-x86_64.sh

apt-get install openjdk-8-jdk


apt install python3-dev python3-pip

pip install -U --user pip six numpy wheel setuptools mock
pip install -U --user keras_applications==1.0.6 --no-deps
pip install -U --user keras_preprocessing==1.0.5 --no-deps



git clone https://github.com/tensorflow/tensorflow.git
cd tensorflow


git checkout r1.12

./configure  # answer prompts or use defaults

bazel build --config=opt //tensorflow/tools/pip_package:build_pip_package

./bazel-bin/tensorflow/tools/pip_package/build_pip_package /mnt  # create package

chown $HOST_PERMS /mnt/tensorflow-1.12.0.whl

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment