我正在尝试使用docker容器运行我的vite+react应用程序,代码运行良好,但不幸的是,它没有在localhost 3000中打开
DockerFile
FROM node:18-alpine
EXPOSE 3000
WORKDIR /react-vite-app
COPY package.json .
RUN yarn install
COPY . .
CMD [ "yarn","build"]docker-compose.yml
version: "3.8"
services:
reactapp:
build: ./dir
container_name: react_vite_app
ports:
- '3000:3000'有什么遗漏了吗?如果有什么不对劲的地方,请帮助我解决这个问题。
发布于 2022-10-20 12:30:27
我从同一个配置中得到了完全相同的问题,我在这里找到了解决方案:
发布于 2022-11-04 09:04:26
将vite配置中的端口设置为3000
import { defineConfig } from 'vite'
import reactRefresh from '@vitejs/plugin-react-refresh'
// https://vitejs.dev/config/
export default defineConfig({
server: {
host: '0.0.0.0',
port: 3000,
},
plugins: [ your plugins here ],
})也像这样经营码头
FROM node:18-alpine
WORKDIR /react-vite-app
EXPOSE 3000
COPY package.json package-lock.json ./
RUN npm install --silent
COPY . ./
CMD ["npm", "run", "dev"]发布于 2022-09-06 15:24:03
我的设置
Dockerfile
FROM node:18-alpine
WORKDIR /app
COPY . /app
ENV NODE_ENV=production
RUN npm install serve -g
RUN npm install
RUN npm run build
EXPOSE 3000
CMD ["npm", "run", "serve"]package.json
{
"name": "frontend",
"private": true,
"version": "0.0.0",
"scripts": {
"dev": "vite -p 3000",
"build": "tsc && vite build",
"preview": "vite preview",
"serve": "serve -s dist -p 3000"
},
"dependencies": {
...
},
"devDependencies": {
...
}
}https://stackoverflow.com/questions/73623891
复制相似问题