챗봇 ELSA에 사용할 Docker Image를 만들어 hub에 띄웠습니다.

지금 제가 프로젝트로 개발중인 챗봇 ELSA는 주변의 상황을 인지하여 사용자에게 먼저 말을 건네주는 챗봇입니다.

상황을 인지하기 위해 darknet/YOLO Object Detector를 사용하며, django를 서버 framework로 사용합니다.

이때 YOLO는 딥러닝 기반 Object Detector로써, CUDA 및 GPU성능을 요구합니다.

지금까지는 yolo-tiny를 사용하여 cpu로 구동했으나, 속도와 성능의 문제가 있었습니다.

이를 극복하기 위해 아마존 AWS EC2에 YOLO 모델을 올리고 opencv에서 제공하는 dnn모듈을 사용하여 구동할 예정입니다.

이를 위하여 docker이미지를 제작하고 hub 및 github에 업로드했습니다.

 ELSA-docker Github  ELSA-docker Dockerhub

  1. Dockerfile 만들기
  2. Docker image build하기
  3. Github로 푸시하기
  4. Dockerhub로 푸시하기

자, 이제 시작하겠습니다.

via GIPHY

1. Dockerfile 만들기

먼저 Dockerfile을 만들었습니다.

사용한 모듈은 다음과 같습니다.

# ==================================================================
# module list                   ver/branch  source
# ------------------------------------------------------------------
# python3                       latest      pip
# opencv                        3.4.2       git
# Mecab                         latest      git
# ELSA-server                   latest      git
# ELSA-client                   latest      git
# ELSA-situation-recognition    opencv      git
# ==================================================================

이때, ELSA-* 모듈은 private repository로써 현재 collaborator만 접근이 가능합니다.

mkdir ~/docker  #원하는 경로를 설정합니다.
cd ~/docker
vim Dockerfile #Dockerfile을 작성합니다.

아래와 같이 만들어 주었습니다.

# https://www.learnopencv.com/install-opencv3-on-ubuntu/

FROM nvidia/cuda:8.0-cudnn5-devel-ubuntu16.04
LABEL maintainer "eungbean@yonsei.ac.kr"
ENV OPENCV_VERSION 3.4.2

# Install all dependencies for OpenCV
RUN APT_INSTALL="apt-get install -y --no-install-recommends" && \
    PIP_INSTALL="python -m pip --no-cache-dir install --upgrade" && \

    apt-get -y update && \
    $APT_INSTALL \
        python3 \
        python3-dev \
        git \
        wget \
        unzip \
        cmake \
        build-essential \
        pkg-config \
        libatlas-base-dev \
        gfortran \
        libjasper-dev \
        libgtk2.0-dev \
        libavcodec-dev \
        libavformat-dev \
        libswscale-dev \
        libjpeg-dev \
        libpng-dev \
        libtiff-dev \
        libjasper-dev \
        libv4l-dev \
    && \

# install python dependencies
    wget https://bootstrap.pypa.io/get-pip.py && \
    python3 get-pip.py && \
    rm get-pip.py && \
    pip3 install numpy \
    && \

# Install OpenCV
    wget https://github.com/opencv/opencv/archive/$OPENCV_VERSION.zip -O opencv3.zip && \
    unzip -q opencv3.zip && \
    mv /opencv-$OPENCV_VERSION /opencv && \
    rm opencv3.zip && \
    wget https://github.com/opencv/opencv_contrib/archive/$OPENCV_VERSION.zip -O opencv_contrib3.zip && \
    unzip -q opencv_contrib3.zip && \
    mv /opencv_contrib-$OPENCV_VERSION /opencv_contrib && \
    rm opencv_contrib3.zip \
    && \

# Prepare build
    mkdir /opencv/build && cd /opencv/build && \
    cmake -D CMAKE_BUILD_TYPE=RELEASE \
      -D BUILD_PYTHON_SUPPORT=ON \
      -D CMAKE_INSTALL_PREFIX=/usr/local \
      -D OPENCV_EXTRA_MODULES_PATH=/opencv_contrib/modules \
      -D BUILD_EXAMPLES=OFF \
      -D PYTHON_DEFAULT_EXECUTABLE=/usr/bin/python3 \
      -D BUILD_opencv_python3=ON \
      -D BUILD_opencv_python2=OFF \
      -D WITH_IPP=OFF \
      -D WITH_FFMPEG=ON \
      -D WITH_CUDA=ON \
      -D CUDA_TOOLKIT_ROOT_DIR=/usr/local/cuda-8.0 \
      -D WITH_CUBLAS=ON \
      -D WITH_V4L=ON .. \
    && \

# Install
    cd /opencv/build && \
    make -j$(nproc) && \
    make install && \
    ldconfig \
    && \

# Clean
   apt-get -y remove \
        python3-dev \
        libatlas-base-dev \
        gfortran \
        libjasper-dev \
        libgtk2.0-dev \
        libavcodec-dev \
        libavformat-dev \
        libswscale-dev \
        libjpeg-dev \
        libpng-dev \
        libtiff-dev \
        libjasper-dev \
        libv4l-dev \
    && \
    apt-get clean && \
    rm -rf /opencv /opencv_contrib /var/lib/apt/lists/* && \

# ==================================================================
#ELSA-SERVER
# ==================================================================

  $APT_INSTALL \
    CacheControl==0.12.5 \
    cachetools==2.1.0 \
    certifi==2018.10.15 \
    chardet==3.0.4 \
    coreapi==2.3.3 \
    coreschema==0.0.4 \
    Django==2.1.2 \
    django-cors-headers==2.4.0 \
    django-environ==0.4.5 \
    django-split-settings==0.3.0 \
    djangorestframework==3.9.0 \
    firebase-admin==2.13.0 \
    google-api-core==1.5.1 \
    google-auth==1.5.1 \
    google-cloud-core==0.28.1 \
    google-cloud-firestore==0.30.0 \
    google-cloud-storage==1.13.0 \
    google-resumable-media==0.3.1 \
    googleapis-common-protos==1.5.3 \
    grpcio==1.16.0 \
    hgtk==0.1.3 \
    idna==2.7 \
    itypes==1.1.0 \
    Jinja2==2.10 \
    JPype1==0.6.3 \
    konlpy==0.5.1 \
    MarkupSafe==1.0 \
    msgpack==0.5.6 \
    numpy==1.15.3 \
    pandas==0.23.4 \
    protobuf==3.6.1 \
    psycopg2-binary==2.7.5 \
    pyasn1==0.4.4 \
    pyasn1-modules==0.2.2 \
    python-dateutil==2.7.5 \
    pytz==2018.7 \
    requests==2.20.0 \
    rsa==4.0 \
    six==1.11.0 \
    uritemplate==3.0.0 \
    urllib3==1.24 \
    curl && \

# Mecab
    curl -s https://raw.githubusercontent.com/konlpy/konlpy/master/scripts/mecab.sh && \

# Git clone
    mkdir ~/ELSA \
    cd ~/ELSA && \
    git clone https://github.com/gyukebox/elsa-server && \

# ==================================================================
#ELSA-situation-recognition
# ==================================================================
    git clone https://github.com/gyukebox/ELSA-situation-recognition.git &&\
# ==================================================================

# ==================================================================
#ELSA-Client
# ==================================================================

    APT_INSTALL npm &&\

    # Git clone
    cd ~/ELSA &&\
    git clone https://github.com/gyukebox/ELSA-client.git
# ==================================================================


# Define default command.
CMD ["python3 --version"]

# variables for display
# ENV DISPLAY=unix$DISPLAY
# VOLUME ["/dev/snd:/dev/snd \"]
# VOLUME ["/tmp/.X11-unix:/tmp/.X11-unix"]

# Variable for webcam
# DEVICE ["/dev/video0:/dev/video0"]

2. 빌드하기

sudo docker build --t eungbean/elsa -f Dockerfile .

확인하기

sudo docker image ls

3. github에 Push하기

git init
git remote add origin git@github.com:eungbean/ELSA-docker.git
git add .
git commit -m "first commit"
git push

4. dockerhub에 올리기

로그인을 하고 docker에 올립니다. 아이디와 비밀번호를 요구할 것입니다.

#Login
sudo docker Login
# docker push <Docker Hub 사용자 계정>/<이미지 이름>:<태그>
sudo docker push eungbean/ELSA:py3-cuda

성공적으로 올라갔습니다!

Comments

Eungbean Lee's Picture

About Eungbean Lee

Lee is a Student, Programmer, Engineer, Designer and a DJ

Seoul, South Korea https://eungbean.github.io