本dockerfile是在通过dockerfile构建tensorflow+opencv的镜像(ubuntu+python3+ffmpeg)基础上增加是jupyter的相关安装。
步骤1:编写Dockerfile
步骤2:安装镜像
步骤3:验证安装
步骤1:编写Dockerfile
1、在目录/dockerfiles/tensorflow-opencv-jupyter下创建一个Dockerfile
mkdir /dockerfiles
mkdir /dockerfiles/tensorflow-opencv-jupyter
vi /dockerfiles/tensorflow-opencv-jupyter/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 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
步骤2:安装镜像
docker build -t lld2002/python3-tensorflow-opencv-jupyter /dockerfiles/tensorflow-opencv-jupyter
步骤3:验证安装
1、创建一个jupyter_notebook_config.py文件放置到/notebooks目录下,内容如下
## Whether to allow the user to run the notebook as root.
c.NotebookApp.allow_root = True
## The IP address the notebook server will listen on.
c.NotebookApp.ip = '*'
## The directory to use for notebooks and kernels.
c.NotebookApp.notebook_dir = '/root/notebooks'
# The string should be of the form type:salt:hashed-password.
c.NotebookApp.password ='sha1:a40ddd427052:620cd5d12a9a8d47a2bdaf45139e22f90be2e2d3' #密码为 'tensorflow'
# any user can connect to the notebook server via ssh.
c.NotebookApp.password_required = True
## The port the notebook server will listen on.
c.NotebookApp.port = 8888
2、通过镜像生成容器,并运行
mkdir /notebooks
docker run -p 8888:8888 -v /notebooks:/root/notebooks -it lld2002/python3-tensorflow-opencv-jupyter:latest jupyter notebook --config /root/notebooks/jupyter_notebook_config.py
3、打开浏览器http://127.0.0.1:8888/tree
密码输入: tensorflow
则测试成功