vite 打包docker,宿主和镜像无法联通
-
在vite.config.js中按如下配置,以及导出端口
import { defineConfig } from 'vite' import vue from '@vitejs/plugin-vue' // https://vitejs.dev/config/ export default defineConfig({ plugins: [vue()], server: { watch: { usePolling: true, }, host: true, // needed for the Docker Container port mapping to work strictPort: true, port: 5173, // you can replace this port with any port } })
-
Dockerfile 编写
FROM node WORKDIR /app COPY package.json . RUN npm i COPY . . EXPOSE 5173 CMD ["npm", "run", "dev"]