MongoDB
FROM centos:centos7
MAINTAINER The CentOS Project <[email protected]>
RUN yum -y update; yum clean all
RUN yum -y install epel-release; yum clean all
RUN yum -y install mongodb-server; yum clean all
RUN mkdir -p /data/db
EXPOSE 27017
ENTRYPOINT ["/usr/bin/mongod"]
参考:
Redis
FROM centos:centos7
MAINTAINER The CentOS Project <[email protected]>
LABEL 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 all
COPY redis-master.conf /redis-master/redis.conf
COPY redis-slave.conf /redis-slave/redis.conf
COPY entrypoint /entrypoint
RUN mkdir /redis-master-data && \
chmod 755 /entrypoint /redis-master-data && \
chown 997 /redis-master-data
EXPOSE 6379
# By default will run as random user on openshift and the redis user (997)
# everywhere else
USER 997
CMD [ "/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
:
Flask
requests
Dockerfile
:
FROM python:3.7
LABEL maintainer="michael"
ENV LANG C.UTF-8
COPY . /app
COPY ./.pip/pip.conf ~/.pip/pip.conf
WORKDIR /app
RUN 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.com
docker push registry.domain.com/michael/get-ip:latest
因为网络的原因,无法直接连接 pypi 官方源,所以,在 pip install
时,使用了 --proxy
参数来指定代理。
Flask 参考
Pip 代理
- Github-pip doesn't respect proxy while installing packages from requirements file
- SOF-Pip inside dockerfile under proxy
- SOF-Customize ONBUILD environment in a dockerfile 问题中附上了 pip 源设置的官方连接
参考
- Docker 快速入门 某公司的内部指导,有参考意义