程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Running Django and Vue on docker

編輯:Python

stay Docker Up operation Django and Vue

Run Django and Vue on Docker

Django Dockerfile

Generate django Project dependency package .

Generate Django project dependencies.

pip freeze > requirements.txt

To write django The startup script run.sh

Write a Django startup script run.sh

python3 manage.py runserver 0.0.0.0:8000

To write 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

Write build scripts 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

To write 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;
}
}

To write 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

To write Vue Build script

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

stay Docker Up operation Django and 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


Operation and maintenance log of hoist


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved