Docker无法在构建器模式中提取本地构建映像

uajslkp6  于 2022-11-22  发布在  Docker
关注(0)|答案(1)|浏览(258)

我正试图设置一个建立流在我的monorepo与pnpm和涡轮增压。
我的目标是有这样一个结构:

apps/
    web/
       Dockerfile
    api/
       Dockerfile
Dockerfile
package.json
pnpm-lock.yaml
turbo.json

其中根Dockerfile如下所示:

FROM --platform=linux/amd64 node:18-alpine as builder

WORKDIR /usr/src/app

# Prerequisites
RUN apk add --no-cache libc6-compat
RUN apk update
RUN npm install -g pnpm@7.16.0

# Copy dependency definitions
COPY package.json ./
COPY pnpm*.yaml ./
COPY .npmrc ./
RUN pnpm fetch

# Set CI to true to disable lefthook hooks
ENV CI=true

# Copy all other files
COPY . ./

然后/api停靠文件看起来像这样(基于this example):

FROM me/base as base

FROM node:18-alpine as api-builder
WORKDIR /usr/src/app

# Prerequisites
RUN apk add --no-cache libc6-compat
RUN apk update
RUN npm install -g turbo

COPY --from=base /usr/src/app /usr/src/app/
RUN turbo prune --scope=api --docker

FROM node:18-alpine as api-installer
WORKDIR /usr/src/app

# Prerequisites
RUN apk add --no-cache libc6-compat
RUN apk update
RUN npm install -g pnpm@7.16.0

COPY --from=api-builder /usr/src/app/out/json ./
COPY --from=api-builder /usr/src/app/pnpm-lock.yaml ./pnpm-lock.json
RUN pnpm install --filter=api --offline

COPY --from=api-builder /usr/src/app/out/full .
COPY --from=api-builder /usr/src/app/turbo.json ./turbo.json

FROM node:18-alpine as api-runner
WORKDIR /usr/src/app

RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 runner
USER runner

COPY --from=api-installer /app/apps/api/package.json .

COPY --from=api-installer --chown=runner:nodejs /app/apps/api/build ./

ENTRYPOINT [ "node", "apps/api/build/server.js" ]

我从构建基本映像开始,如下所示:
docker build . -t me/base
我仔细检查了图像是否有效构建(docker image ls)。
接下来,我尝试在/apps/api内运行Dockerfile
但它失败了:

[+] Building 0.7s (4/4) FINISHED
 => [internal] load build definition from Dockerfile                                                                                                                                                                         0.0s
 => => transferring dockerfile: 1.08kB                                                                                                                                                                                       0.0s
 => [internal] load .dockerignore                                                                                                                                                                                            0.0s
 => => transferring context: 2B                                                                                                                                                                                              0.0s
 => ERROR [internal] load metadata for docker.io/me/base:latest                                                                                                                                                          0.6s
 => CANCELED [internal] load metadata for docker.io/library/node:18-alpine                                                                                                                                                   0.6s
------
 > [internal] load metadata for docker.io/me/base:latest:
------
failed to solve with frontend dockerfile.v0: failed to create LLB definition: pull access denied, repository does not exist or may require authorization: server message: insufficient_scope: authorization failed

我的灵感来自于Docker Multi-Stage: How to split up into multiple Dockerfiles
如何确保它不是从docker.io而是从我的本地构建映像中提取?
注意:我知道可以有一些优化,但作为第一个版本,我首先希望有这个设置工作。

hgc7kmma

hgc7kmma1#

好的,我这里的问题是我必须在基本映像中使用--platform=linux/amd64,以确保prisma依赖关系仍然有效。
这意味着我还必须在后续图像中使用它,因为否则它无法找到本地(然后是ARM64,因为我在m1 mac上)图像。

相关问题