Ubuntu18.04镜像制作

Dockfile

#!/bin/bash
FROM ubuntu:18.04
RUN ln -snf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo Asia/Shanghai > /etc/timezone
ENV LANG C.UTF-8

EXPOSE  20998
COPY .  /data/code

RUN  sed -i s@/archive.ubuntu.com/@/mirrors.aliyun.com/@g /etc/apt/sources.list && \
     apt-get clean && \
     apt-get update --fix-missing && \
     apt-get install -y libmysqlclient-dev tzdata  \
                        python3 python3-dev python3-pip redis-server vim net-tools \
    && apt-get clean \
    && apt-get autoclean \
	&& ln -s /usr/bin/pip3 /usr/bin/pip && ln -s /usr/bin/python3 /usr/bin/python \

	&& pip3 install -r /data/code/requirements.txt -i https://mirrors.aliyun.com/pypi/simple  \
	&& rm -rf /var/lib/apt/lists/*
# --- install requirements ---
WORKDIR /data/code
RUN chmod +x /data/code/start_script.sh
# --- running service ---
CMD  /bin/bash  start_script.sh

python3.7镜像制作

#!/bin/bash
FROM python:3.7-stretch
RUN ln -snf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo Asia/Shanghai > /etc/timezone
EXPOSE  8899
COPY .  /data/code

# --- install requirements ---

RUN pip install --no-cache-dir --user --default-timeout=100 -i https://mirrors.aliyun.com/pypi/simple/ -r  /data/code/requirements.txt

# --- running service ---
WORKDIR /data/code
CMD ["python", "main.py"]

start_script.sh

#!/bin/bash
nohup  redis-server&

PYTHONIOENCODING=utf-8  python3 main.py

镜像容器制作

docker build -t server_api:v2 .
docker run -itd -p 18899:8899  -v   /home/irecog/server_api:/data/code    --name      server_api    server_api:v2

Docker官网:https://docs.docker.com/
参考:https://zhuanlan.zhihu.com/p/340931592

posted @ 2021-09-08 10:19  离人怎挽_wdj  阅读(326)  评论(0编辑  收藏  举报