【发布时间】:2021-03-11 20:37:16
【问题描述】:
我正在尝试对具有 php 后端和 vuejs 前端的应用程序进行 dockerize。后端按我的预期工作,但是在前端容器中运行npm run build 后,我需要将构建文件从 dist 文件夹复制到 nginx 容器或托管,然后使用卷将这些文件带到 nginx 容器。
我尝试使用命名卷
services:
frontend:
.....
volumes:
- static:/var/www/frontend/dist
nginx:
.....
volumes:
- static:/var/www/frontend/dist
volumes:
static:
我还尝试按照此处的建议执行以下操作,以将 dist 文件夹带回主机
services:
frontend:
.....
volumes:
- ./frontend/dist:/var/www/frontend/dist
但是,以上选项都不适合我。下面是我的 docker-compose.yml 文件和前端 Dockerfile
version: "3"
services:
database:
image: mysql:5.7.22
.....
backend:
build:
context: ./docker/php
dockerfile: Dockerfile
.....
frontend:
build:
context: .
dockerfile: docker/node/Dockerfile
target: 'build-stage'
container_name: frontend
stdin_open: true
tty: true
volumes:
- ./frontend:/var/www/frontend
nginx:
build:
context: ./docker/nginx
dockerfile: Dockerfile
container_name: nginx
restart: unless-stopped
ports:
- 80:80
volumes:
- ./backend/public:/var/www/backend/public:ro
- ./frontend/dist:/var/www/frontend/dist:ro
depends_on:
- backend
- frontend
前端 Dockerfile
# Develop stage
FROM node:lts-alpine as develop-stage
WORKDIR /var/wwww/frontend
COPY /frontend/package*.json ./
RUN npm install
COPY /frontend .
# Build stage
FROM develop-stage as build-stage
RUN npm run build
【问题讨论】:
标签: node.js docker vue.js nginx docker-compose