最近的兩個小項目,2:Python webapp的docker鏡像

時間過得真快,一眨眼一個多月沒更新了,但這一個月我可沒偷懶啊,真的是忙。粘上兩篇ReadMe勉強湊合一下,保持博客更新是好習慣。

基於Flask框架,uwsgi起服務,supervisor做管理,應該算是很靈活的了。

flask - docker

Docker image of python webapp.

Pre-installed uwsgi & supervisor, base on python:2.7-alpine


– File structure –

path/to/app
    - src  # Put your webapp(s) source code hear.
        -- static
        -- templates
        -- application.py
        ...
        # Folder|module is permitted hear for more then one app.
        -- app1
            ...
        -- app2
            ...
        ...
    - share  # Used to share with host|other-contains.
        -- static/...  # Convenience to service static files by nginx.
        -- tmp/uwsgi.sock  # Convenience to connect.
        -- app3  # Convenience to develop and debug.
        ...
    - programs.conf  # Config-file for supervisor.
    - requirements.txt  # Install your dependencies.

– Build image –

First, add your “Dockerfile”:
FROM zhengxiaoyao0716/flask

MAINTAINER ${your name}

EXPOSE  port1 port2 ...
Now, you can build your webapp image:
docker build -t <yourImageName> .

– Start container –

docker run --name <appName> \
    -p <host-port>:<port> \
    -v <volumeDir>:/web/share \
    -d <yourImageName>
  • –name= Assign a name to the container
  • -p, –publish=[] Publish a container’s port(s) to the host
  • -v, –volume=[] Bind mount a volume
  • -d, –detach=false Run container in background and print container ID

Now your container will running in background.

Maybe you need to enter it:
docker exec -it <appName> /bin/sh
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章