Dockerfile 打包Django项目

Python官方docker镜像库

  https://hub.docker.com/_/python/

  https://github.com/docker-library/python

 

编写DockerFile

FROM python:3.8.2-alpine3.11
LABEL description='Django project for MyWeb'

WORKDIR /usr/src/app
copy ./MyWeb ./myweb

WORKDIR myweb/
RUN pip3 install django && pip3 install gunicorn

  ENTRYPOINT /usr/local/bin/gunicorn --bind 0.0.0.0:80 myweb.wsgi:application

 

打包Docker镜像

当前目录下有Django项目MyWeb

[root@~]# docker build -t myweb:v1 .
Sending build context to Docker daemon  172.5kB
Step 1/7 : FROM python:3.8.2-alpine3.11
 ---> d5e5ad4a4fc0
Step 2/7 : LABEL description='Django project for MyWeb'
 ---> Using cache
 ---> 1110d9098f8f
Step 3/7 : WORKDIR /usr/src/app
 ---> Using cache
 ---> 001400cf6307
Step 4/7 : copy ./MyWeb ./myweb
 ---> Using cache
 ---> 9f5ab05db11e
Step 5/7 : WORKDIR myweb/
 ---> Using cache
 ---> b09b8c5d28b1
Step 6/7 : RUN pip3 install django && pip3 install gunicorn
 ---> Using cache
 ---> cc3923a6bbc1
Step 7/7 : ENTRYPOINT /usr/local/bin/gunicorn --bind 0.0.0.0:80 myweb.wsgi:application
---> Using cache
 ---> 1dd9e08294ff
Successfully built 1dd9e08294ff
Successfully tagged myweb:v1
[root@10923870-jinkenst workspace]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED              SIZE
myweb               v1                  1dd9e08294ff        About a minute ago   146MB
python              3.8.2-alpine3.11    d5e5ad4a4fc0        3 weeks ago          107MB 

 

上传到Harbor

# docker login -u admin -p Harbor12345 harbor.vmware.com
# docker tag myweb:v1 harbor.vmware.com
/library/myweb:v1
# docker push harbor.vmware.com
/library/myweb:v1

 

你可能感兴趣的:(Dockerfile 打包Django项目)