在Docker上运行Django和Vue

在Docker上运行Django和Vue

Run Django and Vue on Docker

Django Dockerfile

生成django项目依赖包.

Generate Django project dependencies.

pip  freeze > requirements.txt

编写django启动脚本 run.sh

Write a Django startup script run.sh

python3 manage.py runserver 0.0.0.0:8000

编写 Django Dockerfile

Write a Dockerfile for django

FROM python:alpine3.8

ADD ./bthlt_backend /bthlt_backend/bthlt_backend
ADD ./requirements.txt /bthlt_backend/
ADD ./manage.py /bthlt_backend/
ADD ./run.sh /bthlt_backend/


WORKDIR /bthlt_backend
RUN pip install -r ./requirements.txt

# Define default command.
CMD ["/bin/sh", "run.sh"]

# Expose ports.
EXPOSE 8000

编写构建脚本 build_run.sh

Write a script for build_run.sh

#!/bin/bash
docker build -t 123.bthlt.com/bthlt_backend:$1 .
docker push 123.bthlt.com/bthlt_backend:$1
bash build_run.sh v0.0.1

Vue Dockerfile

编写nginx.conf

Write nginx.conf

server {
    listen       80;
    server_name  localhost;

    location /api/ {
     proxy_pass http://bthlt-backend:8000/;
    }

    location / {
        root /usr/src/app/;
        index  index.html index.htm;

        gzip_types text/plain application/javascript application/x-javascript text/css application/xml text/javascript;
        gzip on;

        if_modified_since off;
        etag off;
        add_header Last-Modified "";


        if (!-e $request_filename) {
            rewrite ^/[^.]+$  /index.html break;
        }
    }

    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   html;
    }
}

编写Dockerfile

Write Dockerfile

FROM nginx:mainline-alpine-perl

ADD ./nginx.conf /etc/nginx/conf.d/default.conf
ADD ./dist/ /usr/src/app/

# Define default command.
CMD ["nginx", "-g", "daemon off;"]

# Expose ports.
EXPOSE 80

编写Vue构建脚本

Write Vue build script

#!/bin/bash
yarn build
docker build -t 123.bthlt.com/bthlt_front:$1 .
docker push 123.bthlt.com/bthlt_front:$1
bash build_run.sh v0.0.1

在Docker上运行Django和Vue

Run Django and Vue on Docker

docker run  --name bthlt-backend -d -p 8000:8000 123.bthlt.com/bthlt_backend:v0.0.1
docker run  --name bthlt-front -d -p 80:80 --link bthlt-backend:bthlt-backend 123.bthlt.com/bthlt_front:v0.0.1

葫芦的运维日志

本站文章资源均来源自网络,除非特别声明,否则均不代表站方观点,并仅供查阅,不作为任何参考依据!
如有侵权请及时跟我们联系,本站将及时删除!
如遇版权问题,请查看 本站版权声明
THE END
分享
二维码
海报
在Docker上运行Django和Vue
在Docker上运行Django和Vue Run Django and Vue on Docker Django Dockerfile 生成django项目依赖包. Generate Django project dependencies. pip freeze &……
<<上一篇
下一篇>>