linux 在Docker上运行Django和Vue

葫芦的运维日志

下一篇 搜索 上一篇

浏览量 2672

2021/09/08 21:54


在Docker上运行Django和Vue

Run Django and Vue on Docker

Django_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

葫芦的运维日志

打赏

上一篇 搜索 下一篇
© 冰糖葫芦甜(bthlt.com) 2021 王梓打赏联系方式 陕ICP备17005322号-1