Commit aa9acc79 by 周田

部署

parent b72e3d42
version: '3'
services:
device_web_dockerfile:
# 通过 dockerfile 创建镜像
# build:
# context: .
# dockerfile: Dockerfile
# 如果使用上面的内容下面 image 就不需要了
image: device_web_dockerfile_compose
container_name: device_web
tty: true
# 容器的网络模式,如果使用 host 模式,就不需要下面 ports 的内容
# ports 的内容是在默认的网络模式 bridge 的情况下设置的
network_mode: host
# ports:
# - "8080:8080"
# 文件映射,会将整个目录全部替换
# volumes:
# - .:/app
environment:
TZ: "Asia/Shanghai"
entrypoint: "python manage.py runserver 0.0.0.0:8080"
device_web:
build: .
command: daphne vue_django.asgi:application --port 8000 --bind 0.0.0.0
network_mode: "host"
volumes:
- .:/app
ports:
- "8000:8000"
nginx:
image: nginx
network_mode: "host"
ports:
- "10000:10000"
depends_on:
- device_web
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf
- ./static:/app/static
\ No newline at end of file
# 使用的环境
FROM ubuntu:20.04
FROM python:3.9.18
# 升级 apt-get 和 下载 python3.9
# DEBIAN_FRONTEND="noninteractive" 禁用交互
RUN apt-get update && DEBIAN_FRONTEND="nointeractive" apt-get install -y \
python3.9 \
python3.9-venv \
python3.9-dev \
python3-pip
# 工作目录为 /app
# 意味着进入容器后的目录为 /app
WORKDIR /app
# 将当前目录下的所有内容拷贝到 /app 目录下
COPY . .
COPY . /app
# 使用 python3.9 创建虚拟环境
RUN python3.9 -m venv ./venv
# 将虚拟环境添加到 PATH 中
ENV PATH="/app/venv/bin:$PATH"
# 使用虚拟环境中的 pip3.9 安装 poetry
RUN pip3.9 install poetry -i https://pypi.tuna.tsinghua.edu.cn/simple
# 使用 poetry 下载项目所需要的依赖
# poetry config virtualenvs.create false 为禁用创建虚拟环境
# 即直接将内容下到刚刚创建的虚拟环境中
RUN poetry config virtualenvs.create false && poetry install
RUN pip install poetry
RUN poetry config virtualenvs.create false && poetry install --no-dev --no-interaction --no-ansi
# 向外部暴露 8000 端口
EXPOSE 8000
# 启动容器后运行的命令
ENTRYPOINT ["python", "manage.py", "runserver", "0.0.0.0:8000" ]
CMD ["daphne", "vue_django.asgi:application", "--port", "8000", "--bind", "0.0.0.0"]
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log notice;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
include /etc/nginx/conf.d/*.conf;
upstream web {
# server device_web:8000;
server localhost:8000;
}
server {
listen 10000;
server_name localhost;
location / {
root /app/static;
index index.html;
}
location /api {
proxy_pass http://web;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Accept application/json;
}
location /ws/ {
proxy_pass http://web;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
}
}
}
{
"systemParams": "linux-x64-93",
"modulesFolders": [
"node_modules"
],
"flags": [],
"linkedModules": [],
"topLevelPatterns": [],
"lockfileEntries": {},
"files": [],
"artifacts": {}
}
\ No newline at end of file
......@@ -134,7 +134,7 @@ STATIC_URL = '/static/'
# STATIC_ROOT = os.path.join(BASE_DIR, 'static')
STATIC_ROOT = 'static'
STATICFILES_DIRS = [
# os.path.join(BASE_DIR, 'frontend', 'dist'),
os.path.join(BASE_DIR, 'frontend', 'dist'),
# os.path.join(BASE_DIR, 'static'),
]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment