MongoDB
FROM centos:centos7MAINTAINER The CentOS ProjectRUN yum -y update; yum clean allRUN yum -y install epel-release; yum clean allRUN yum -y install mongodb-server; yum clean allRUN mkdir -p /data/dbEXPOSE 27017ENTRYPOINT ["/usr/bin/mongod"]
参考:
Redis
FROM centos:centos7MAINTAINER The CentOS ProjectLABEL io.k8s.description="Redis is an open source, in-memory data structure store, used as database, cache and message broker." \ io.k8s.display-name="Redis 2.8.19-2.el7" \ io.openshift.expose-services="6379:redis" \ io.openshift.tags="database,redis,redis3"LABEL Name="centos/redis-28-centos7" \ Version="2.8.19" \ Release="2" \ Architecture="x86_64"RUN yum -y --setopt=tsflags=nodocs update && \ yum -y --setopt=tsflags=nodocs install epel-release && \ yum -y --setopt=tsflags=nodocs install redis && \ yum clean allCOPY redis-master.conf /redis-master/redis.confCOPY redis-slave.conf /redis-slave/redis.confCOPY entrypoint /entrypointRUN mkdir /redis-master-data && \ chmod 755 /entrypoint /redis-master-data && \ chown 997 /redis-master-dataEXPOSE 6379# By default will run as random user on openshift and the redis user (997)# everywhere elseUSER 997CMD [ "/entrypoint" ]ENTRYPOINT [ "sh", "-c" ]
参考:
部署 Flask 应用
当前目录是get-pip
,目录结构如下:
$ tree ..├── app.py├── Dockerfile├── README.md└── requirements.txt
app.py
:
# coding:utf-8 from flask import request, Flask app = Flask(__name__) @app.route("/ip", methods=["GET"]) def get_my_ip(): return request.remote_addr @app.route('/', methods=["GET"]) def hello_world(): return 'Hello World! From IP: {}'.format(get_my_ip()) if __name__ == '__main__': # 默认的端口就是 5000,你可以指定其他端口,例如 8081 app.run(port=5000, host='0.0.0.0', debug=True)
requirements.txt
:
Flaskrequests
Dockerfile
:
FROM python:3.7LABEL maintainer="michael"ENV LANG C.UTF-8COPY . /appCOPY ./.pip/pip.conf ~/.pip/pip.confWORKDIR /appRUN pip install -r requirements.txt --proxy="http://127.0.0.1:3128"ENTRYPOINT ["python"]CMD ["app.py"]
在get-pip
目录下,构建镜像:
docker build -t registry.domain.com/michael/get-ip:latest .
推送镜像:
docker login -u micahel registry.domain.comdocker push registry.domain.com/michael/get-ip:latest
因为网络的原因,无法直接连接 pypi 官方源,所以,在 pip install
时,使用了 --proxy
参数来指定代理。
Flask 参考
Pip 代理
- 问题中附上了 pip 源设置的官方连接
参考
- 某公司的内部指导,有参考意义