Commit aa9acc79 by 周田

部署

parent b72e3d42
version: '3' version: '3'
services: services:
device_web_dockerfile: device_web:
# 通过 dockerfile 创建镜像 build: .
# build: command: daphne vue_django.asgi:application --port 8000 --bind 0.0.0.0
# context: . network_mode: "host"
# dockerfile: Dockerfile volumes:
# 如果使用上面的内容下面 image 就不需要了 - .:/app
image: device_web_dockerfile_compose ports:
container_name: device_web - "8000:8000"
tty: true nginx:
# 容器的网络模式,如果使用 host 模式,就不需要下面 ports 的内容 image: nginx
# ports 的内容是在默认的网络模式 bridge 的情况下设置的 network_mode: "host"
network_mode: host ports:
# ports: - "10000:10000"
# - "8080:8080" depends_on:
- device_web
# 文件映射,会将整个目录全部替换 volumes:
# volumes: - ./nginx.conf:/etc/nginx/nginx.conf
# - .:/app - ./static:/app/static
environment: \ No newline at end of file
TZ: "Asia/Shanghai"
entrypoint: "python manage.py runserver 0.0.0.0:8080"
# 使用的环境 FROM python:3.9.18
FROM ubuntu:20.04
# 升级 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 WORKDIR /app
# 将当前目录下的所有内容拷贝到 /app 目录下 COPY . /app
COPY . .
# 使用 python3.9 创建虚拟环境 RUN pip install poetry
RUN python3.9 -m venv ./venv RUN poetry config virtualenvs.create false && poetry install --no-dev --no-interaction --no-ansi
# 将虚拟环境添加到 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
# 向外部暴露 8000 端口
EXPOSE 8000 EXPOSE 8000
# 启动容器后运行的命令 CMD ["daphne", "vue_django.asgi:application", "--port", "8000", "--bind", "0.0.0.0"]
ENTRYPOINT ["python", "manage.py", "runserver", "0.0.0.0:8000" ]
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/' ...@@ -134,7 +134,7 @@ STATIC_URL = '/static/'
# STATIC_ROOT = os.path.join(BASE_DIR, 'static') # STATIC_ROOT = os.path.join(BASE_DIR, 'static')
STATIC_ROOT = 'static' STATIC_ROOT = 'static'
STATICFILES_DIRS = [ STATICFILES_DIRS = [
# os.path.join(BASE_DIR, 'frontend', 'dist'), os.path.join(BASE_DIR, 'frontend', 'dist'),
# os.path.join(BASE_DIR, 'static'), # 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