Django Heroku Docker Container registory and runtime 用のimageとDockerfileの保存
概要
ちょっと粗いけど、一応 django+anaconda3+opencv3 のimageをheroku docker containerに登録できたので、それをまとめてみる。
やってみたこと
- anaconda3(ubuntu)のDockerfileをgithubにアップロード
- anaconda3のimageをautomated build して、docker hubに保存
- そのdocker hubのimageを継承したdjango+opencv3のDockerfileをgithubにアップロード
anaconda3(ubuntu)のDockerfileをgithubにアップロード
GitHub - yassyskywalker/anaconda3-ubuntu: anaconda3-ubuntu for docker
これをdocker hubからautomated create
する。
https://hub.docker.com/r/nabladesignlabs/anaconda3-ubuntu/
これがちゃんと動くか、localPCで確認する。
docker run -it nabladesignlabs/anaconda3-ubuntu /bin/bash
一応動いたけど、以下のerrorが発生
bash: warning: setlocale: LC_ALL: cannot change locale (ja_JP.UTF-8)
ここはあんまりいじらない方が良さそうだな、、、ということで、デフォルトの設定に戻すことにする。
ENV LANG=C.UTF-8 LC_ALL=C.UTF-8
これで、OK。次は、nabladesignlabs/anaconda3-ubuntu
継承して、django+opencvをinstallするDockerfileを用意する。
nabladesignlabs/anaconda3-ubuntuの上に、django+opencvをinstallするimageを重ねるDockerfileを追加する。
# Dockerfile FROM nabladesignlabs/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 libgtk2.0-0 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
とりあえず、まずはlocalのホストPCにimageを作って、containerを起動・生成してみる。
$ docker build -t djanopencv3-heroku ./ $ docker run -it djanopencv3-heroku /bin/bash $ 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 >>> import matplotlib >>> import scipy >>> import numpy
cv2なども、importできた!後はこれをherokuにpushしてみる。
$ heroku container:login $ heroku create djangonda-opencv3 $ heroku container:push web --app djangonda-opencv3 $ heroku open --app djangonda-opencv3
これで動いた!とりあえず、これをgit hubにアップしておこう。
git hubのレポジトリにpushしてみる。
$ git add . $ git commit -m "first commit" $ git remote add origin https://github.com/yassyskywalker/heroku-django-anaconda3-opencv3.git $ git push -u origin master
以下のerrorが出てしまった。
hint: Updates were rejected because the remote contains work that you do hint: not have locally. This is usually caused by another repository pushing hint: to the same ref. You may want to first integrate the remote changes hint: (e.g., 'git pull ...') before pushing again. hint: See the 'Note about fast-forwards' in 'git push --help' for details.
うーん、どうも よくわらないので、ググってみた。
これは自分がリモートの変更をpullしてから、pushするまでの間に、他からのpushがあるなどしてリモートが変更されているためです。
とのこと。もうよくわからんので、とりあえず、諦めて、新しいリポジトリ作ります。
$ git add . $ git commit -m "first commit" $ git remote add origin https://github.com/yassyskywalker/opencv3-django.git $ git push -u origin master
これでgithubに登録完了!
GitHub - yassyskywalker/opencv3-django: opencv3,django,anaconda3
これでheroku docker container registory and runtimeとの戦いは一旦休戦!