Docker - Trying to dockerize my Django app
I've spent sometime messing around the docker engine for couple days. I guess It's time to try dockerizing my Django app.
Assuming I have already created a Ubuntu Trusty image , open a container:
* The container (by default: eth0 - 172.17.0.2): python2.7, pip, virtualenv, mysql-client
* The host machine (by default: docker0 - 172.17.42.1): mysql-server, grant permisson to the container host:
MariaDB [(none)]> use appdb;
MariaDB [appdb]> grant all privileges on appdb.* to 'myuser'@'172.17.0.2' identified by 'mypassword';
(mydjangoenv)root@93b3f27d3129:~# git clone https//my.git.repo/myproject
(mydjangoenv)root@93b3f27d3129:~# cd myproject
(mydjangoenv)root@93b3f27d3129:~# pip install -r requirements.txt
(mydjangoenv)root@93b3f27d3129:~# ./manage run 0.0.0.0:8000
(remember to add the container's hostname (93b3f27d3129) to ALLOWED_HOSTS )
Assuming I have already created a Ubuntu Trusty image , open a container:
- Prerequisites:
* The container (by default: eth0 - 172.17.0.2): python2.7, pip, virtualenv, mysql-client
* The host machine (by default: docker0 - 172.17.42.1): mysql-server, grant permisson to the container host:
MariaDB [(none)]> use appdb;
MariaDB [appdb]> grant all privileges on appdb.* to 'myuser'@'172.17.0.2' identified by 'mypassword';
- Inside the container:
(mydjangoenv)root@93b3f27d3129:~# git clone https//my.git.repo/myproject
(mydjangoenv)root@93b3f27d3129:~# cd myproject
(mydjangoenv)root@93b3f27d3129:~# pip install -r requirements.txt
(mydjangoenv)root@93b3f27d3129:~# ./manage run 0.0.0.0:8000
(remember to add the container's hostname (93b3f27d3129) to ALLOWED_HOSTS )
- In the host machine: Open the browser, enter 172.17.0.2:8000 to use the app.
- Final step: commit the changes of the container on the host machine to create a new image
$ sudo docker commit 93b3f27d3129 mydjangoapp
Now I have a dockerized django app.
Comments
Post a Comment