在Dockerfile中运行yarn install时无法获取node_modules文件夹
test-sof
├── docker-compose.yml
├── Dockerfile
├── package.json
└── yarn.lock
docker-compose.yml
version: '3'
services:
web:
build: .
volumes:
- .:/myapp
包.json
{
"name": "site",
"private": true,
"dependencies": {
"@rails/webpacker": "^3.2.1",
"babel-preset-react": "^6.24.1",
"prop-types": "^15.6.0",
"react": "^16.2.0",
"react-dom": "^16.2.0",
"reactjs": "^1.0.0",
"underscore": "^1.8.3"
},
"devDependencies": {
"webpack-dev-server": "^2.11.1"
}
}
多克弗菲勒
FROM ruby:2.5
RUN curl -sL https://deb.nodesource.com/setup_8.x | bash - && \
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - && \
echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list && \
apt-get update && \
apt-get install -qq -y build-essential libpq-dev nodejs yarn
RUN mkdir /myapp
WORKDIR /myapp
ADD ./package.json /myapp/
RUN yarn install
运行纱线安装步骤的输出docker-compose 构建:
Step 6/6 : RUN yarn install
---> Running in 3a0e7095ec81
yarn install v1.3.2
info No lockfile found.
[1/4] Resolving packages...
[2/4] Fetching packages...
info [email protected] /cdn-cgi/l/email-protection: The platform "linux" is incompatible with this module.
info "[email protected] /cdn-cgi/l/email-protection" is an optional dependency and failed compatibility check. Excluding it from installation.
[3/4] Linking dependencies...
warning "@rails/webpacker > [email protected] /cdn-cgi/l/email-protection" has unmet peer dependency "caniuse-lite@^1.0.30000697".
warning " > [email protected] /cdn-cgi/l/email-protection" has unmet peer dependency "webpack@^2.2.0 || ^3.0.0".
warning "webpack-dev-server > [email protected] /cdn-cgi/l/email-protection" has unmet peer dependency "webpack@^1.0.0 || ^2.0.0 || ^3.0.0".
[4/4] Building fresh packages...
success Saved lockfile.
Done in 21.11s.
Removing intermediate container 3a0e7095ec81
---> 5720579a0f2a
Successfully built 5720579a0f2a
Successfully tagged testsof_web:latest
运行命令:docker-compose 运行 web bash进入容器
root@11af1818e494:/myapp# ls
Dockerfile docker-compose.yml package.json
不存在 node_modules 文件夹,但稍后在容器内运行时:纱线安装 output:
root@11af1818e494:/myapp# yarn install
yarn install v1.3.2
info No lockfile found.
[1/4] Resolving packages...
[2/4] Fetching packages...
info [email protected] /cdn-cgi/l/email-protection: The platform "linux" is incompatible with this module.
info "[email protected] /cdn-cgi/l/email-protection" is an optional dependency and failed compatibility check. Excluding it from installation.
[3/4] Linking dependencies...
warning "@rails/webpacker > [email protected] /cdn-cgi/l/email-protection" has unmet peer dependency "caniuse-lite@^1.0.30000697".
warning " > [email protected] /cdn-cgi/l/email-protection" has unmet peer dependency "webpack@^2.2.0 || ^3.0.0".
warning "webpack-dev-server > [email protected] /cdn-cgi/l/email-protection" has unmet peer dependency "webpack@^1.0.0 || ^2.0.0 || ^3.0.0".
[4/4] Building fresh packages...
success Saved lockfile.
Done in 13.03s.
然后列出时:
root@11af1818e494:/myapp# ls
Dockerfile docker-compose.yml node_modules package.json yarn.lock
文件夹node_modules 存在。为什么?