无法通过 docker 构建安装纱线包



我正在尝试通过将yarn.lock中的所有当前软件包都安装在映像上来加速docker的启动。我认为我的纱线安装不正确,它在其他地方工作?

Docker文件的相关部分:

# Create a dir
WORKDIR /(WORKDIR)
# Time to install all our dependencies
COPY package.json /(WORKDIR)/package.json
COPY yarn.lock /(WORKDIR)/yarn.lock
# Need the executables to be in the path
ENV PATH /(WORKDIR)/node_modules/.bin:$PATH
RUN yarn check --verify-tree || yarn install --frozen-lockfile

我认为我的最后一行不正确。它正在某处安装,但不安装在软件包本身上?无论是缓存还是缓存都可能是一个问题。如果我启动图像,我发现yarn check --verify-tree的输出仍然是图像的当前状态。

我在 Docker 构建期间无法yarn install。我收到网络错误(getaddrinfo EAI_AGAIN(:

Step 6/8 : COPY yarn.lock /app/yarn.lock
---> Using cache
---> e55488a3d051
Step 7/8 : RUN yarn
---> Running in 5bb8d663d00b
yarn install v1.22.15
[1/4] Resolving packages...
[2/4] Fetching packages...
error An unexpected error occurred: "https://registry.yarnpkg.com/app-root-path/-/app-root-path-3.0.0.tgz: getaddrinfo EAI_AGAIN registry.yarnpkg.com".
info If you think this is a bug, please open a bug report with the information provided in "/app/yarn-error.log".
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
ERROR: Service 'web-svc' failed to build: The command '/bin/sh -c yarn' returned a non-zero code: 1

我最近更新了我的Ubuntu Linux系统,并认为这可能是原因。因此,我重新启动了docker.service并解决了问题。

sudo systemctl restart docker.service

只需RUN yarn并确保COPY代码库yarn.

FROM        node:12.14.0-alpine3.11
ENV         NODE_ENV=production
WORKDIR     /app
COPY        package.json ./
COPY        yarn.lock ./
RUN         yarn
COPY        src ./

我在我的机器上测试它,你可以看看我是否改变了yarn.lock.如果我不改变我的yarn.lock

$ docker build -t demo .
Step 1/6 : FROM        node:12.14.0-alpine3.11
---> 1cbcaddb8074
Step 2/6 : ENV         NODE_ENV=production
---> Using cache
---> dc7f1a2f7d90
Step 3/6 : WORKDIR     /app
---> Using cache
---> eec9363713a5
Step 4/6 : COPY        package.json ./
---> Using cache
---> fde6cf7bb577
Step 5/6 : COPY        yarn.lock ./
---> 6a1369622d79
Step 6/6 : RUN         yarn
---> Running in ff6433969bea
yarn install v1.21.1
[1/4] Resolving packages...
[2/4] Fetching packages...
warning sha.js@2.4.11: Invalid bin entry for "sha.js" (in "sha.js").
warning url-loader@1.1.2: Invalid bin field for "url-loader".
info fsevents@1.2.9: The platform "linux" is incompatible with this module.
info "fsevents@1.2.9" is an optional dependency and failed compatibility check. Excluding it from installation.
[3/4] Linking dependencies...
warning " > styled-components@5.0.1" has unmet peer dependency "react-is@>= 16.8.0".
[4/4] Building fresh packages...
Done in 35.97s.
Removing intermediate container ff6433969bea
---> 8dcd2124289d
Successfully built 8dcd2124289d
$docker build -t demo .
Step 1/6 : FROM        node:12.14.0-alpine3.11
---> 1cbcaddb8074
Step 2/6 : ENV         NODE_ENV=production
---> Using cache
---> dc7f1a2f7d90
Step 3/6 : WORKDIR     /app
---> Using cache
---> eec9363713a5
Step 4/6 : COPY        package.json ./
---> Using cache
---> fde6cf7bb577
Step 5/6 : COPY        yarn.lock ./
---> Using cache
---> 6a1369622d79
Step 6/6 : RUN         yarn
---> Using cache
---> 8dcd2124289d
Step 7/7 : COPY        src ./
---> 13474b882e11

最新更新