本dockerfile是在通过dockerfile构建tensorflow+opencv的镜像(ubuntu+python3+ffmpeg)基础上增加是jupyter的相关安装。
步骤1:编写Dockerfile
步骤2:安装镜像
步骤3:验证安装
步骤1:编写Dockerfile
1、在目录/dockerfiles/tensorflow-opencv-jupyter--otherlibs下创建一个Dockerfile
mkdir /dockerfiles
mkdir /dockerfiles/tensorflow-opencv-jupyter-otherlibs
vi /dockerfiles/tensorflow-opencv-jupyter-otherlibs/Dockerfile
2、Dockerfile的内容如下:
FROM ubuntu:16.04
RUN apt-get update
RUN apt-get upgrade -y
# Install python3
RUN apt-get install -y python3
# Install pip
RUN apt-get install -y wget vim
RUN wget -O /tmp/get-pip.py https://bootstrap.pypa.io/get-pip.py
RUN python3 /tmp/get-pip.py
RUN pip install --upgrade pip
# Install other libs
RUN pip install -U numpy
RUN pip install -U matplotlib
RUN pip install -U pandas
# Install tensorflow
RUN pip install -U tensorflow
# Install ffmpeg
RUN apt-get install -y ffmpeg
# Install moviepy
RUN pip install -U moviepy
# Install cmake
RUN apt-get update
RUN apt-get install -y build-essential
RUN apt-get install -y cmake
# Install OpenCV
RUN apt-get install -y unzip
RUN wget -P /usr/local/src/ https://github.com/opencv/opencv/archive/3.4.1.zip
RUN cd /usr/local/src/ && unzip 3.4.1.zip && rm 3.4.1.zip
RUN cd /usr/local/src/opencv-3.4.1/ && mkdir build
RUN cd /usr/local/src/opencv-3.4.1/build && cmake -D CMAKE_INSTALL_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local/ .. && make -j4 && make install
# Install opencv-python
RUN pip install opencv-python
RUN apt-get install -y libsm6
RUN apt-get install -y libxrender1
RUN apt-get install -y libxext-dev
# Install python-dev
RUN apt-get update
RUN apt-get install -y python-dev
# Install jupyter notebook
RUN pip install jupyter
RUN pip install notebook
由于numpy和tensorflow的有版本冲突,所以numpy等的基础libs必须在tensorflow前进行安装
步骤2:安装镜像
docker build -t lld2002/python3-tensorflow-opencv-jupyter-otherlibs /dockerfiles/tensorflow-opencv-jupyter-otherlibs
步骤3:验证安装
1、通过镜像生成容器,并运行
docker run -it lld2002/python3-tensorflow-opencv-jupyter-otherlibs:latest /bin/bash
2、在容器的终端中,创建一个/test.py的文件
vi /test.py
3、test.py的内容如下:
import tensorflow as tf
import numpy as np
import matplotlib as mlib
import pandas
4、运行/test.py
python3 /test.py
控制台无报错
则测试成功
本文提供了一种使用Dockerfile构建包含TensorFlow、OpenCV及Jupyter的Ubuntu镜像的方法,详细介绍了Dockerfile的编写过程及镜像构建步骤。
1821

被折叠的 条评论
为什么被折叠?



