Skip to content
Benny_Ray edited this page May 3, 2020 · 4 revisions

Quick Start

  • Make sure there's a docker engine (version >= 18) installed on the host. If not, please refer to Get Docker Engine - Community for Ubuntu;
  • Open a terminal on the host and type the following command;
user@machine:~$ docker run -it --rm --network host raniac/neuro-learn-docker:dev
  • Obtain the host's IP address using command ifconfig, then open a browser on another machine under the same LAN with the host and type the address. VOILA!
  • More information about NEURO-LEARN per se can be found in NEURO-LEARN Documentation.

Advanced | Build your own NEURO-LEARN-DOCKER

Build Docker Image Using Commit and Dockerfile

  • Pull base image dockerfiles/django-uwsgi-nginx
$ docker pull dockerfiles/django-uwsgi-nginx
  • Initiate container
$ docker run -it --rm --network host -v /home/bennyray:/home/bennyray dockerfiles/django-uwsgi-nginx /bin/bash
  • Install mysql-server and mysql-client
$ apt update
$ apt upgrade -y
$ apt install mysql-server
$ apt install mysql-client
$ apt install libmysqlclient-dev
$ mysql -u root -h 127.0.0.1 -p // check if mysql service works
  • Install rabbitmq-server
$ apt install rabbitmq-server
  • Install Python3.6
$ apt install software-properties-common
$ add-apt-repository ppa:jonathonf/python-3.6
$ apt update
$ apt install python3.6
$ python3.6 -m pip install --upgrade pip
  • Install python dependencies
# install freezed dependencies of NLW
$ pip3.5 install -r requirements.txt -i https://pypi.doubanio.com/simple
# further install dependencies of celery tasks
$ pip3.6 install {module name} -i https://pypi.doubanio.com/simple
# {module name} include sklearn, statsmodels, etc.
  • Configure nginx and uwsgi
$ cd /etc/nginx
$ mv nginx.conf nginx.conf.backup # backup original nginx.conf
$ cp /home/bennyray/Projects/neuro-learn/web/nginx.conf . # configure nginx
$ service nginx start # start nginx
$ service rabbitmq-server start # start rabbitmq
$ cd /home/bennyray/Projects/neuro-learn/web/neurolearn_dev/
$ uwsgi -d uwsgi.log uwsgi.ini // start uwsgi
$ export C_FORCE_ROOT='True' # enable celery to run with root
$ python3.6 manage.py celeryd -l info # start celery
  • Commit image
$ docker ps
CONTAINER ID        IMAGE                            COMMAND             CREATED             STATUS              PORTS                    NAMES
35d5ffeab1b1        dockerfiles/django-uwsgi-nginx   "/bin/bash"         3 hours ago         Up 3 hours                                   brave_lumiere
$ docker commit 35d5ffeab1b1 neuro-learn-docker:base
  • Push base image
$ docker tag neuro-learn-docker:base raniac/neuro-learn-docker:base
$ docker push raniac/neuro-learn-docker:base
  • Edit start.sh
service nginx start;
service rabbitmq-server start;
cd /neuro-learn/app/;
uwsgi -d uwsgi.log uwsgi.ini;
export C_FORCE_ROOT='True';
python3.6 manage.py celeryd -l info;
  • Edit Dockerfile
FROM raniac/neuro-learn-docker:base
MAINTAINER raniac <leibingye@outlook.com>

WORKDIR /neuro-learn
ADD . /neuro-learn/

RUN cp -f /neuro-learn/nginx.conf /etc/nginx

CMD ["sh","/neuro-learn/start.sh"]
  • Build dev image and push
$ docker build -t raniac/neuro-learn-docker:dev .
$ docker push raniac/neuro-learn-docker:dev
  • Run container
$ docker run -it --rm --network host raniac/neuro-learn-docker:dev
# Or if you need to check the logs
$ docker run -it --rm --network host raniac/neuro-learn-docker:dev /bin/bash
$ nohup sh start.sh >> celery.log &
$ cat celery.log # Check the celery logs
$ cat app/uwsgi.log # Check the uwsgi logs

Update Docker Images Using Commit and Dockerfile

  • Update base image
$ docker run -it --rm --network host raniac/neuro-learn-docker:base /bin/bash
# Do whatever is necessaray and commit changes in another bash process
$ docker ps
CONTAINER ID        IMAGE                            COMMAND             CREATED
35d5ffeab1b1        dockerfiles/django-uwsgi-nginx   "/bin/bash"         3 hours ago
$ docker commit 35d5ffeab1b1 raniac/neuro-learn-docker:base
$ docker push raniac/neuro-learn-docker:base
  • Update dev image
# Update project files and build the image with Dockerfile
$ docker build -t raniac/neuro-learn-docker:dev .
$ docker push raniac/neuro-learn-docker:dev

Deploy Online Database

  • Create Database
mysql> create database neurolearn;
  • Create User and Grant Privileges
mysql> create user 'neurolearn'@'%' identified by 'nl4444_';
/*host="localhost"为本地登录用户,host="ip"为ip地址登录,host="%",为外网ip登录*/
mysql> grant all privileges on `neurolearn`.* to 'neurolearn'@'%' IDENTIFIED BY 'nl4444_';
mysql> flush privileges;
  • Open Remote Port for Database
$ sudo ufw allow 3306
  • Set Django DB Connection
$ docker run -it --rm raniac/neuro-learn-docker:dev /bin/bash
# Django: app/neurolearn/settings.py
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'neurolearn',
        'USER': 'neurolearn',
        'PASSWORD': 'nl4444_',
        'HOST': '120.79.49.129',
        'PORT': '3306',
    }
}
  • Sync Database
$ python3.6 manage.py makemigrations
$ python3.6 manage.py migrate
$ docker ps
CONTAINER ID        IMAGE                            COMMAND             CREATED             STATUS              PORTS                    NAMES
35d5ffeab1b1        raniac/neuro-learn-docker:dev   "/bin/bash"         3 hours ago         Up 3 hours                                   brave_lumiere
$ docker commit 35d5ffeab1b1 raniac/neuro-learn-docker:dev