Docker – get start guide

I’ve discover the love for python language, I’ve tried django route but I think is too complicated for beginning of programming python, then I’ve discover flask, is much simpleper to develop small apps quickly, I’ve try to develop simple app locally, connect to database and render out data to a page, then how to deploy it to the World Wide Web? There are ways such as deploy to Heroku, Amazon lambda, Google cloud platform etc… all of those are not free. 

And here is my Synology NAS comes into play, I am running DSM 6.1 and it support Docker. At first I though I build a Ubuntu server to host the app and route the port 80 connection to the container for the world to see, but it was not that easy, first Ubuntu server images are all shipped with python 2.7, but my app are build on python 3.6 another issue is I cannot install MySQL into the Ubuntu server image, error was something like “cannot find the working directory” I guess the /var/lib/mysql directory could not be created during the apt install process.

So then, I dig deeper into docker, do some more research, find out that docker’s concept is to seperate a large application into micro process, I was so fascinated about this concept, then I’ve learned how to link the app container to the database container. It turns out quite simple. Here is the video how to do it. And also it do not need a Ubuntu server image to build it, all it need is only the python3.6 image! So cool!

To create db server

I use mariadb, for database server is simple, just run the image to create the container, and specify root password, and I expose 33061 port because I want to use my MySQL client to connect to the database server on my local machine.

docker run – name dbserver -e MYSQL_ROOT_PASSWORD=test -d -p 33061:3306 mariadb

Because when container destroy, it will lose its state, so here use -v switch to map an host directory to container db directory so when the instance destroy, it just only need to run the following command again and all the data will still be there.

docker run -d — name dbserver -e MYSQL_ROOT_PASSWORD=test -v /volume1/Code/PYTHON/myflaskapp/database/data:/var/lib/mysql -p 33061:3306 mariadb

To build the app server

I use python:3.6

To create the container, I use Dockerfile to build the image

FROM python:3.6
 RUN mkdir /opt/myflaskapp
 WORKDIR /opt/myflaskapp
 COPY requirements.txt /opt/myflaskapp
 RUN pip install – no-cache-dir -r requirements.txt
 COPY . /opt/myflaskapp
 CMD [“python3.6", “”]

run the docker file

docker build -t flask_app_server .

To run the image

docker run -id -p 80:5000 -v /volumn1/Code/PYTHON/myflaskapp:/opt/myflaskapp – name myflaskapp – link dbserver:mysql flask_app_serve


I am so excited I’ve learned docker, it makes develop programs so much easier, when it comes to deploying time, just export the container with contents and settings and then import it to the docker host and the app is ready to serve to the world wide web.

My GitHub docker_notes:

Docker – Kitematic (The GUI)

Here you can get the GUI for docker, it is develop using Electron, so the program should be alike across Windows, Mac and linux. Currently you can get the program via the GitHub page – link here:

Log In

How to Use Docker + Webtop to Secure Your Online Activities