django+Vue的项目使用docker打包

django项目迁移

①在项目根目录下,创建Dockerfile文件:

# 使用官方 Python 镜像作为基础
FROM python:3.9.18
# 设置工作目录
WORKDIR /app
# 复制项目文件
COPY . /app
# 安装依赖
RUN pip install --upgrade pip && \
    pip install -r requirements.txt
# 开放端口(假设你用的是8000)
EXPOSE 8000
# 启动命令
CMD ["python", "manage.py", "runserver", "0.0.0.0:8000"]

②打包

docker build -t 镜像名 .

③创建容器

docker  run -p  8000:8000 --name  容器名 镜像名

 

vue项目迁移

①构建项目

npm run build

②在项目根目录下,创建nginx.conf:

server {
    listen 80;
    server_name _;
    root /usr/share/nginx/html;
    index index.html index.htm;
​
    location / {
        try_files $uri $uri/ /index.html;
    }
​
    location ~* \.(js|css|png|jpg|jpeg|gif|svg|ico|json)$ {
        try_files $uri =404;
    }
}

③在项目根目录下,创建Dockerfile文件:

FROM nginx:alpine
COPY dist/ /usr/share/nginx/html/
COPY nginx.conf /etc/nginx/conf.d/default.conf
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]

④打包

docker build -t 镜像名 .

⑤创建容器

docker run -d -p 8080:80 --name 容器名 镜像名
posted @ 2025-07-29 19:06  台友涛  阅读(19)  评论(0)    收藏  举报