Heroku Docker Container registory and runtime で、django+anaconda3にさらにopencv3を加えてみる!
概要
django+anaconda3にさらにopencv3を加えてみる!
参考サイト
やってみた
先日の記事で作成したdjango+anaconda3にさらにopencv3を加えてみる。 anacondaでopencvを入れるときは、condaで入れると楽らしいので、それを使ってみる。
Dockerfile
#Grab the latest alpine image FROM anaconda3-ubuntu # Install python and pip RUN apt-get update && apt-get install -y --no-install-recommends postgresql-client python-pip build-essential libpq-dev python3-dev ADD requirements.txt /usr/src/app/requirements.txt # Install dependencies RUN pip install setuptools RUN pip install -r /usr/src/app/requirements.txt RUN conda install -y --channel https://conda.anaconda.org/menpo opencv3 # Add our code ADD . /usr/src/app/ WORKDIR /usr/src/app # Expose is NOT supported by Heroku # EXPOSE 5000 # Run the image as a non-root user RUN useradd -m myuser USER myuser # Run the app. CMD is required to run on Heroku # $PORT is set by Heroku CMD gunicorn --bind 0.0.0.0:$PORT gettingstarted.wsgi
これで、buildしてみる。
$ docker build -t djanopencv3 ./
とりあえずbuild成功!
ちゃんとopencvが入っているか確認してみる。
$ docker run -it djanopencv3 /bin/bash myuser****:/usr/src/app$ python >>> import cv2 Traceback (most recent call last): File "<stdin>", line 1, in <module> ImportError: libgtk-x11-2.0.so.0: cannot open shared object file: No such file or directory
installはされたけど、開けないとのこと。。。ググったら、以下のような解決策が上がっていた。
At least in Ubuntu 16.04, libgtk2.0-0 contains libgtk-x11-2.0.so.0, so apt-get install libgtk2.0-0 works.
参考サイト:
apt - Installing libgtk-x11-2.0.so.0 in Ubuntu 15.04 - Ask Ubuntu
なので、libgtk2.0-0
のinstallをDockerfileに付け加えて、再度buildしてみる。
# Dockerfile ... RUN apt-get update && apt-get install -y --no-install-recommends postgresql-client python-pip build-essential libpq-dev python3-dev libgtk2.0-0 ...
$ docker build -t djanopencv3-2 ./
とりあえず、buildは無事完了した! 問題は、import cv2が使えるか。。。
$ docker run -it djanopencv3-2 /bin/bash myuser@*******:/usr/src/app$ python Python 3.5.2 |Anaconda 4.2.0 (64-bit)| (default, Jul 2 2016, 17:53:06) [GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import cv2 >>>
おーー、errorが出なかった!多分、使えるね!
次は、これを元に、herokuにpushしてみる。
$ heroku container:login $ heroku create djangonda-cv3 $ heroku container:push web --app djangonda-cv3 $ heroku open --app djangonda-cv3
OK!開いた!
ただ、めちゃくちゃ重いので、これだときつそうだな〜w