[PYTHON] Try running tensorflow on Docker + anaconda


Since I bought a new PC, I used Docker to build a python environment and run CNN. Since Docker is almost a beginner, I will take this opportunity to study.
As the flow this time

    1. Get the official anaconda3 image on Docker
  1. Create a container based on the anaconda3 image
    1. Introduce tensorflow to anaconda3 Four. Open Jupyter Noteook from your browser Five. Increase Docker memory
  2. Build a CNN using tensorflow It has become.


1. 1. Get the official anaconda3 image on Docker

anaconda is an open source platform that has all the essential packages for data science practitioners. I am grateful to use this because there is an image of anaconda3 from the official.


Now, start Docker and get the image of Anaconda3.

% docker pull continuumio/anaconda3

Using default tag: latest
latest: Pulling from continuumio/anaconda3
68ced04f60ab: Pull complete
57047f2400d7: Pull complete
8b26dd278326: Pull complete
Digest: sha256:6502693fd278ba962af34c756ed9a9f0c3b6236a62f1e1fecb41f60c3f536d3c
Status: Downloaded newer image for continuumio/anaconda3:latest

pull is a command to get a Docker image.

2. Create a container based on the anaconda3 image

Next, we will create a container.

% docker run --name anaconda -it -p 8888:8888 -v /Users/xxxx/docker/anaconda:/home continuumio/anaconda3 /bin/bash
(base) root@xxxx:/# conda list

The meaning of each command and option is as follows.

3. 3. Introduce tensorflow to anaconda3

Let's check the packages that are pre-installed on anaconda3.

base) root@xxxx:/# conda list
# packages in environment at /opt/conda:
# Name                    Version                   Build  Channel
_ipyw_jlab_nb_ext_conf    0.1.0                    py37_0  
_libgcc_mutex             0.1                        main  
alabaster                 0.7.12                   py37_0  
anaconda                  2020.02                  py37_0  
anaconda-client           1.7.2                    py37_0  
anaconda-navigator        1.9.12                   py37_0  
anaconda-project          0.8.4                      py_0  
argh                      0.26.2                   py37_0  
asn1crypto                1.3.0                    py37_0  
astroid                   2.3.3                    py37_0  
astropy                   4.0              py37h7b6447c_0  
atomicwrites              1.3.0                    py37_1  
attrs                     19.3.0                     py_0  
yaml                      0.1.7                had09818_2  
yapf                      0.28.0                     py_0  
zeromq                    4.3.1                he6710b0_3  
zict                      1.0.0                      py_0  
zipp                      2.2.0                      py_0  
zlib                      1.2.11               h7b6447c_3  
zstd                      1.3.7                h0b5b093_0  

The docker command cannot be used because it is in the anaconda3 container. Look at the package in the conda list available on the anaconda terminal.
Since anaconda3 does not have tensorflow installed from the beginning, use conda install Install tensorflow and its peripheral packages.

base) root@xxxx:/# conda install tensorflow

Four. Open Jupyter Notebook from your browser

You can open the Jupyter Notebook, which you used to love when you were in college, from your browser.

base) root@xxxx:/# jupyter notebook --port 8888 --ip= --allow-root
To access the notebook, open this file in a browser:
    Or copy and paste one of these URLs:

Enter the URL at the end into your browser to launch Jupyter Notebook.

Five. Increase Docker memory

Before building CNN, Docker can only use up to 2G of memory by default, so if you try to train with CNN, it will overflow. So I will change the setting so that it can be used up to 7G.

  1. Click the Docker icon at the top of your desktop
  2. Click Preference
  3. Click the Resources tab
  4. Set Memory to 7G スクリーンショット 2020-07-15 22.12.29.png

6. Build a CNN using tensorflow

Finally, we will build CNN. For the dataset, download the standard CIFAR10, and use the three convolution layers, the adam method for optimization, and the cross entropy error for the loss function. スクリーンショット 2020-07-09 22.45.21.png
I was able to import tensorflow without any problems, and the memory did not overflow, so this is the end of environment construction!

At the end

I tried touching Docker with a light feeling, but it was too deep and I was addicted to the swamp ... Introducing tensorflow to anaconda3 and opening Jupyter Notebook, which was probably quite difficult for experienced Docker users. There is no loss in doing Docker, so I would like to actively use it. For the time being, I was able to build an environment where tensorflow can be operated, so I will try various deep learning in this environment from now on.

Recommended Posts

Try running tensorflow on Docker + anaconda
Try running Distributed TensorFlow on Google Cloud Platform
Run TensorFlow Docker Image on Python3
Use Tensorflow 2.1.0 with Anaconda on Windows 10!
Try running Jupyter Notebook on Mac
Try using Bash on Windows 10 2 (TensorFlow installation)
Build CGI Server running on Python 3 on Docker
Try running PlaidML image judgment on Mac
Try running Kobuki's 3D simulator on ROS
pykintone on Docker
Try Distributed TensorFlow
Theano on Anaconda
Try running Pyston 0.1
Try Tensorflow with a GPU instance on AWS
Try Apache Spark on Jupyter Notebook (on local Docker
Try running Amazon Timestream
Install Tensorflow on Mac
Install TensorFlow on Ubuntu
[Environment construction] @anaconda that runs keras / tensorflow on GPU
Install docker on Fedora31
Try running a Django application on an nginx unit
Anaconda on Windows Terminal
Install Anaconda on Windows 10
From running MINST on TensorFlow 2.0 to visualization on TensorBoard (2019 edition)
Build TensorFlow on Windows
Try FEniCS on Windows!
Install Docker on AWS
Try Poerty on Windows
Solution for inaccessible Gin server running on Docker container
Try NeosVR on Linux
Try regression with TensorFlow
I tried running TensorFlow
Try deepdream on Mac
Install Python 3.6 on Docker
Install cvxopt on 64bit Anaconda
Try deep learning with TensorFlow
Try using Jupyter's Docker image
Anaconda environment construction on CentOS7
Try StyleGAN on Google Colaboratory
Introduced Tensorflow (Win / Anaconda environment)
Install cvxpy on windows, Anaconda
Try using OpenCV on Windows
Try running CNN with ChainerRL
Install module on Anaconda (Mac)
Run Tensorflow 2.x on Python 3.7
Try "100 knocks on data science" ①
Introducing TensorFlow on Ubuntu + Python 2.7
Try running Python with Try Jupyter
Try Selenium Grid with Docker
[Tensorflow] Tensorflow environment construction on Windows 10
Run IPython Notebook on Docker
Install Docker on WSL Ubuntu 18.04
Notes on installing Anaconda 3 on Windows
Try TensorFlow MNIST with RNN
Try building JupyterHub with Docker
Try using folium with anaconda
Install TensorFlow 1.15.0 on Raspberry Pi
Try running Discord Bot on an iPhone you no longer use
(Note) Notes on building TensorFlow + Flask + Nginx environment with Docker Compose
Environment construction of TensorFlow + JupyterNotebook + Matplotlib on Windows version Anaconda (August 2017 version)