dockerfile打包Python项目环境镜像

1.dockerfile 编写

FROM ubuntu:latest
MAINTAINER jiangmoo

ENV DEBIAN_FRONTEND=noninteractive
ENV LANG C.UTF-8

RUN sed -i "s/security.debian.org/mirrors.aliyun.com/g" /etc/apt/sources.list && \
    apt-get clean && apt-get -y update && \
    DEBIAN_FRONTEND=noninteractive apt-get install -y build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev \
    libssl-dev libreadline-dev libffi-dev libsqlite3-dev wget libbz2-dev \
    python3-dev libevent-dev libhiredis-dev libpq-dev libjpeg-dev libmysqlclient-dev \
    libsasl2-dev libldap2-dev vim nmap python3-pip tzdata

RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
# RUN wget -O /tmp/Python-3.10.5.tar.xz https://www.python.org/ftp/python/3.10.5/Python-3.10.5.tar.xz && \
#     tar -xf /tmp/Python-3.10.5.tar.xz -C /tmp

RUN mkdir -p /scmdb/backend

# WORKDIR /tmp/Python-3.10.5

# RUN ./configure --prefix=/usr/local/lib/python3.10.5/ && \
#     make -j 4 && make -j 4 install

# RUN ln -s /usr/local/lib/python3.10.5/bin/python3.10 /usr/bin/python3.10 && \
#     rm -f /usr/bin/python3 && \
#     ln -s /usr/local/lib/python3.10.5/bin/python3.10 /usr/bin/python3

WORKDIR /scmdb/backend

# RUN rm -rf /tmp/Python-3.10.5.tar.xz && rm -rf /tmp/Python-3.10.5

COPY ./requirements.txt /scmdb/backend

RUN pip3 install --index-url https://mirrors.aliyun.com/pypi/simple/ --no-cache-dir -r requirements.txt

# RUN ln -s /usr/local/lib/python3.10.5/bin/uwsgi /usr/bin/uwsgi

CMD ["bash"]

2. 

docker build -t management:v1 -f Dockerfile/Dockerfile .

3.

docker images

4.

docker save 8396cc >> /Users/mac/Desktop/docker_images/proscmdb.tar

 

二. 将镜像打包到服务器 run起来

1.将打包镜像上传服务器

scp /Users/mac/Desktop/scmdb_docker/scmdb_project_dev_env.tar root@10.33.70.194:/root

2.将镜像导入

docker load < scmdb_project_dev_env.tar

3.将docker run起来

docker run -it --name scmdb -d 6e35 bash

4.查看运行实例

docker ps -a

5.查看docke 全称id

docker inspect -f '{{.ID}}' scmdb

6.上传本地文件到docker内部

docker cp /Users/mac/Desktop/scmdb_docker/tests.py 4cf1da6af2cd7613182cbe6ebf7d80085eeb8347e0223dc3b7163c528025456e:/scmdb/backend

7.docker项目打镜像

docker build -t management:v1 -f Dockerfile/Dockerfile .

 

posted @ 2022-09-24 09:30  Οo白麒麟оΟ  阅读(835)  评论(0编辑  收藏  举报