As a memorandum because I forget how to build it every time.
project
L Dockerfile
L app.py
Dockerfile Since there is a possibility to install a library that uses java, default-jdk is added.
Dockerfile
FROM python:3.6
RUN apt-get update && apt-get install -y \
default-jdk \
build-essential \
gfortran \
libblas-dev \
liblapack-dev \
libxft-dev \
swig \
&& rm -rf /var/lib/apt/lists/*
RUN echo 'export LD_LIBRARY_PATH="/usr/local/lib:$LD_LIBRARY_PATH"' >> ~/.bash_profile && \
. ~/.bash_profile && \
cd ~ &&\
git clone https://github.com/taku910/mecab.git && \
cd mecab/mecab && \
./configure --enable-utf8-only && \
make && \
make check && \
make install && \
cd ../mecab-ipadic && \
./configure --with-charset=utf8 && \
make && \
make install &&\
cd ~ &&\
git clone --depth 1 https://github.com/neologd/mecab-ipadic-neologd.git && \
cd mecab-ipadic-neologd && \
./bin/install-mecab-ipadic-neologd -n -y
RUN pip3 install --upgrade pyzmq --install-option="--zmq=bundled" && \
pip3 install --upgrade jupyter && \
pip3 install --upgrade \
pandas \
neologdn \
Flask \
numpy \
Pillow \
tensorflow \
ENV LD_LIBRARY_PATH "/usr/local/lib:$LD_LIBRARY_PATH"
VOLUME /notebook
WORKDIR /notebook
EXPOSE 8888
ENTRYPOINT jupyter notebook --ip=0.0.0.0 --allow-root --no-browser
Go to the Dockerfile directory and run the docker build command. It will take a few minutes to build.
$ cd project
$ docker build -t image_name --force-rm=true .
# (-t image name)Decide the image name yourself
# (--force-rm=true)If the image build fails, the image will be deleted automatically
When you execute the drawing command, Jupyter notebook will start automatically, so you can use Jupyter notebook by accessing the displayed URL.
#Execute the following command in the same directory as above
$ docker run -v `pwd`:/notebook -p 8888:8888 -p 5000:5000 -it --name container_name image_id /bin/bash
# http://127.0.0.0:8888/?token=####################
#An address like this will appear, so copy and paste each token.
If you are working on Jupyter notebook and want to install the missing libraries, from outside the container, enter the container with the command below.
$ cd project
$ docker exec -it container_name /bin/bash
#When you enter the container with the above command, the terminal will switch as shown below.
root@username:/notebook#You will be able to enter commands here.
#Installation example
root@username:/notebook# pip install numpy
Create app.py in the same directory as Dockerfile and execute the following code and command to start the application.
app.py
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello_world():
return "Hello World!"
if __name__ == '__main__':
app.run()
$ python hello.py
Recommended Posts