Ken*_*imi 5 node.js npm docker dockerfile yarnpkg
我正在尝试为使用纱线安装依赖项的节点应用程序构建 docker 映像。我的 Dockerfile 看起来像这样:
FROM node:7
WORKDIR /app
COPY package.json /app
RUN yarn install
COPY . /app
CMD npm run develop
EXPOSE 8000
Run Code Online (Sandbox Code Playgroud)
当我在本地机器上运行 yarn install 时,一切都运行良好,但是当我进行 docker build 时,我收到了这个永远阻塞的错误。
**docker build -t rs .**
Sending build context to Docker daemon 219.1MB
Step 1/7 : FROM node:7
---> d9aed20b68a4
Step 2/7 : WORKDIR /reason
---> Using cache
---> fe51a1860989
Step 3/7 : COPY package.json /reason
---> Using cache
---> b0e136ee6eeb
Step 4/7 : RUN yarn install
---> Running in e273f8cf1f3e
yarn install v0.24.4
info No lockfile found.
[1/4] Resolving packages...
Couldn't find any versions for "glamor" that matches "next"
? Please choose a version of "glamor" from this list: (Use arrow keys)
? 2.20.40
2.20.39
2.20.38
2.20.37
2.20.36
2.20.35
2.20.34
(Move up and down to reveal more choices)warning glamor@3.0.0-3: abandoned, please use v2 instead
warning gatsby-plugin-glamor > glamor-inline@1.0.5: use glamor/inline instead
warning gatsby-plugin-glamor > glamor-react > glamor@3.0.0-3: abandoned, please use v2 instead
warning gatsby-plugin-glamor > glamor-server > glamor@3.0.0-3: abandoned, please use v2 instead
warning gatsby > babel-preset-es2015@6.24.1: Thanks for using Babel: we recommend using babel-preset-env now:
Run Code Online (Sandbox Code Playgroud)
请阅读 babeljs.io/env 进行更新!
控制台永远停留在这个阶段。我该如何解决这个问题。
Dockerfile
FROM node:6.9.5-alpine
RUN mkdir -p /code
WORKDIR /code
ADD . /code
RUN npm install -g -s --no-progress yarn && \
yarn && \
yarn run build && \
yarn cache clean
CMD [ "npm", "start" ]
EXPOSE 8080
Run Code Online (Sandbox Code Playgroud)
docker-compose.yml
version: '2'
services:
sample-app:
image: sample-node-yarn-app
ports:
- "8080:8080"
Run Code Online (Sandbox Code Playgroud)
创建泊坞窗镜像
docker build -t sample-node-app .
Run Code Online (Sandbox Code Playgroud)
跑步
docker-compose up -d
Run Code Online (Sandbox Code Playgroud)
在构建映像之前,您应该首先运行 yarn install 以生成一个 yarn锁定文件(yarn.lock)。然后确保将它与 package.json 一起复制。您的 dockerfile 应如下所示:
FROM node:7
WORKDIR /app
COPY package.json /app
COPY yarn.lock /app
RUN yarn install
COPY . /app
CMD npm run develop
EXPOSE 8000
Run Code Online (Sandbox Code Playgroud)
有了这个,构建映像时所有依赖项都应该成功安装
| 归档时间: |
|
| 查看次数: |
13727 次 |
| 最近记录: |