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