【发布时间】:2020-12-23 23:36:20
【问题描述】:
我有一个工作方式非常不同的 Docker Compose 环境。
设置如下:
docker-compose.prod.yaml
front_end:
image: front-end-build
build:
context: ./front_end
dockerfile: front_end.build.dockerfile
nginx:
build:
context: ./front_end
dockerfile: front_end.prod.dockerfile
ports:
- 80:80
- 5000:5000
environment:
- CHOKIDAR_USEPOLLING=true
stdin_open: true
tty: true
depends_on:
- front_end
front_end.build.dockerfile
FROM node:13.12.0-alpine
COPY package.json ./
WORKDIR /srv
RUN yarn install
RUN yarn global add react-scripts
COPY . /srv
RUN yarn build
front_end.prod.dockerfile
FROM nginx
EXPOSE 80
COPY --from=front-end-build /app/build /usr/share/nginx/html
COPY nginx.conf /etc/nginx/conf.d
命令:
docker-compose down && docker-compose -f docker-compose.prod.yml up --build --remove-orphans nginx
由于各种原因,在各种运行中它不起作用。
在各种错误之后,我从docker system prune 开始,它至少将问题“重置”到某个起始状态。
各种问题包括:
-
yarn install说info There appears to be trouble with your network connection. Retrying...但随后继续,吐出各种弃用/不兼容警告,最后到达“完成”。- 在此之后,通常可能需要 60 多秒才能显示“正在删除中间容器”并继续 dockerfile 中的下一步。
- 有时我得到的只是网络错误,然后 yarn install 会失败,这会停止整个过程。
-
yarn install可能不会显示该网络错误,但会在“正在解析包”和“正在获取包”之间显示其各种警告,尽管这可能是正常的,但这似乎没有意义。 -
yarn install可能在此过程中的任何时候(包括安装完成后、安装期间,甚至在yarn build期间)报告我们空间不足:error An unexpected error occurred: "ENOSPC: no space left on device, mkdir '/node_modules/fast-glob/package/out/providers/filters'".或类似的东西。
我们可能得到的最远距离是yarn build:
There might be a problem with the project dependency tree.
It is likely not a bug in Create React App, but something you need to fix locally.
The react-scripts package provided by Create React App requires a dependency:
"webpack-dev-server": "3.11.0"
Don't try to install it manually: your package manager does it automatically.
However, a different version of webpack-dev-server was detected higher up in the tree:
/node_modules/webpack-dev-server (version: 3.10.3)
Manually installing incompatible versions is known to cause hard-to-debug issues.
If you would prefer to ignore this check, add SKIP_PREFLIGHT_CHECK=true to an .env file in your project.
That will permanently disable this message but you might encounter other issues.
To fix the dependency tree, try following the steps below in the exact order:
1. Delete package-lock.json (not package.json!) and/or yarn.lock in your project folder.
2. Delete node_modules in your project folder.
3. Remove "webpack-dev-server" from dependencies and/or devDependencies in the package.json file in your project folder.
4. Run npm install or yarn, depending on the package manager you use.
In most cases, this should be enough to fix the problem.
If this has not helped, there are a few other things you can try:
5. If you used npm, install yarn (http://yarnpkg.com/) and repeat the above steps with it instead.
This may help because npm has known issues with package hoisting which may get resolved in future versions.
6. Check if /node_modules/webpack-dev-server is outside your project directory.
For example, you might have accidentally installed something in your home folder.
7. Try running npm ls webpack-dev-server in your project folder.
This will tell you which other package (apart from the expected react-scripts) installed webpack-dev-server.
If nothing else helps, add SKIP_PREFLIGHT_CHECK=true to an .env file in your project.
That would permanently disable this preflight check in case you want to proceed anyway.
P.S. We know this message is long but please read the steps above :-) We hope you find them helpful!
error Command failed with exit code 1.
webpack-dev-server 实际上并没有出现在我的 package.json 文件中的任何地方,所以我没有什么可以改变的,但除此之外我已经尝试了这 4 个步骤。然后下次我运行时出现“没有剩余空间”错误。
我还要说,几乎与此分开,有时,由于某种原因,它会执行所有步骤,除了没有输出 yarn build,甚至没有“使用缓存”。当然,这会使 nginx 容器在尝试获取构建文件时失败。或者类似的东西,老实说已经有一段时间了。 但是当我们继续使用 nginx 时会发生什么,它会说“构建 nginx”一段荒谬的时间,几分钟,甚至在它到达 nginx dockerfile 的第一步之前。
但是前端构建的问题太大了,以至于 nginx 基本上是一个单独的问题。
有没有人经历过(并解决了!)任何类似于我正在经历的事情?
【问题讨论】:
标签: reactjs docker docker-compose yarnpkg