构建多容器docker compose无法构建前端
这是我第一次使用docker compose部署MERN堆栈应用程序。后端(Express服务器和MongoDB)运行良好。我可以通过邮递员发布数据并成功获取数据。但是我的带有NGINX conf代理的React应用程序在构建过程中返回了一个错误构建多容器docker compose无法构建前端,docker,nginx,docker-compose,digital-ocean,mern,Docker,Nginx,Docker Compose,Digital Ocean,Mern,这是我第一次使用docker compose部署MERN堆栈应用程序。后端(Express服务器和MongoDB)运行良好。我可以通过邮递员发布数据并成功获取数据。但是我的带有NGINX conf代理的React应用程序在构建过程中返回了一个错误 production_frontend_1 exited with code 127 frontend_1 | /docker-entrypoint.sh: exec: line 38: yarn: not found frontend_1 | /
production_frontend_1 exited with code 127
frontend_1 | /docker-entrypoint.sh: exec: line 38: yarn: not found
frontend_1 | /docker-entrypoint.sh: exec: line 38: yarn: not found
这是我的档案
FROM node:12.18.2 as build
# RUN npm install -g yarn
WORKDIR /app
ENV NODE_ENV=production
COPY package*.json ./
RUN yarn install && yarn cache clean
COPY . /app
ARG SERVER_APP_API
ARG SERVER_REST_API
ENV SERVER_REST_API ${SERVER_REST_API:-http://localhost:7000/api/v1/}
RUN SERVER_REST_API=${SERVER_REST_API} yarn run build
# ------------------------------------------------------
# Production Build
# ------------------------------------------------------
FROM nginx:alpine
COPY --from=build /app/build /usr/share/nginx/html
RUN rm /etc/nginx/conf.d/default.conf
COPY ./nginx/nginx.conf /etc/nginx/conf.d/default.conf
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
这是我的NGINX.conf
server {
listen 80;
server_name localhost;
location / {
# This would be the directory where your React app's static files are stored at
root /usr/share/nginx/html;
index index.html;
try_files $uri /index.html;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
这是我的docker-compose.yml
version: '3.8'
services:
backend:
ports:
- 5555:5555
build:
context: ./backend
dockerfile: ./Dockerfile
restart: unless-stopped
networks:
- developer-tier
depends_on:
- db
command: npm run start
env_file: ./backend/.env
environment:
- CLIENT_URL=http://localhost:3001/
- NODE_ENV=production
- DATABASE_URL=mongodb://db:27017/developer
frontend:
stdin_open: true
build:
context: ./frontend
dockerfile: ./Dockerfile
ports:
- 3001:3001
restart: unless-stopped
depends_on:
- backend
env_file: ./frontend/.env
networks:
- developer-tier
volumes:
- ./frontend/:/frontend/src/app
- /app/node_modules/
command: yarn start
db:
image: mongo:latest
ports:
- 27017:27017
restart: always
networks:
- developer-tier
volumes:
- dev-data:/data/db
volumes:
dev-data:
driver: local
networks:
developer-tier:
driver: bridge
你评论了你的纱线安装?在第2行中运行npm安装-g warn,只需删除
,或者您可以只运行npm就可以了?npm ERR!代码EEXIST npm ERR!路径../lib/node_modules/warn/bin/warn.js npm ERR!目的地/usr/本地/箱子/纱线npm错误!EEXIST:文件已存在,symlink'../lib/node_modules/warn/bin/warn.js'->'/usr/local/bin/warn'npm ERR!文件存在:/usr/local/bin/thread错误:服务“frontend”构建失败:命令“/bin/sh-c npm install-g thread”返回一个非零代码:239
@Jerryc我在构建时取消注释#RUN npm install-g thread
看起来像是thread附带了节点映像,不确定。@Jerryc当我取消注释#RUN npm install-g warn
时,我在构建时遇到了上述错误。当我返回时,它成功构建并退出,退出代码127