Python服务docker file 的两种方式
方法1:简单方式:FROM python:3.6.8-slim-stretchENV LANG en_US.UTF-8 LC_ALL=en_US.UTF-8COPY . /home/code/news_label_recongnizeRUN cp -f /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \&& cd /home/cod
·
方法1:简单方式:
FROM python:3.6.8-slim-stretch
ENV LANG en_US.UTF-8 LC_ALL=en_US.UTF-8
COPY . /home/code/label_recongnize
RUN cp -f /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
&& cd /home/code/news_label_recongnize \
&& python3 -m pip install --trusted-host mirrors.aliyun.com --no-cache-dir -i http://mirrors.aliyun.com/pypi/simple -r /home/code/label_recongnize/requirements.txt \
&& rm -rf /var/cache/* \
&& rm -rf /tmp/*
ENV PYTHONIOENCODING=utf-8
WORKDIR /home/code/label_recongnize/service
ENTRYPOINT ["python3","test.py","&"]
方法2:
# using ubuntu LTS version
FROM ubuntu:20.04 AS builder-image
# avoid stuck build due to user prompt
ARG DEBIAN_FRONTEND=noninteractive
RUN apt-get update && apt-get install --no-install-recommends -y python3.9 python3.9-dev python3.9-venv python3-pip python3-wheel build-essential && \
apt-get clean && rm -rf /var/lib/apt/lists/*
#配置pip镜像源
# create and activate virtual environment
# using final folder name to avoid path issues with packages
RUN python3.9 -m venv /home/tempuser/venv
ENV PATH="/home/tempuser/venv/bin:$PATH"
# install requirements
COPY requirements.txt .
RUN pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple --no-cache-dir wheel
RUN pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple --no-cache-dir -r requirements.txt
FROM ubuntu:20.04 AS runner-image
RUN apt-get update && apt-get install --no-install-recommends -y python3.9 python3-venv curl telnet vim && \
apt-get clean && rm -rf /var/lib/apt/lists/*
#timezone config
RUN cp -f /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
RUN mkdir /home/tempuser
COPY --from=builder-image /home/tempuser/venv /home/tempuser/venv
RUN mkdir /home/tempuser/code
WORKDIR /home/tempuser/code
COPY . .
EXPOSE 8008
# make sure all messages always reach console
ENV PYTHONUNBUFFERED=1
ENV PYTHONIOENCODING=utf-8
# activate virtual environment
ENV VIRTUAL_ENV=/home/tempuser/venv
ENV PATH="/home/tempuser/venv/bin:$PATH"
# /dev/shm is mapped to shared memory and should be used for gunicorn heartbeat
# this will improve performance and avoid random freezes
ENTRYPOINT ["python3.9","/home/tempuser/code/service/main.py"]
其中CMD和ENTRYPOINT 相关介绍Dockerfile中CMD和ENTRYPOINT的用法_雨还是不停的落下的技术博客_51CTO博客
更多推荐
已为社区贡献1条内容
所有评论(0)