最近的两个小项目,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

转载于:https://www.cnblogs.com/zhengxiaoyao0716/p/5914915.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值