GCR - 图像除了两个文件外全部丢失,本地图像完整

GCR - image missing all but two files, local image is complete

我有一个正在部署到 Kubernetes (GKE) 的容器,我在本地构建的镜像很好,而且 运行 符合预期,但似乎是从 Google Container Registry,当 运行 命令更改为 pwd && ls returns 此处显示的输出:

I 2020-06-17T16:24:54.222382706Z /app
I 2020-06-17T16:24:54.226108583Z lost+found
I 2020-06-17T16:24:54.226143620Z package-lock.json

和 运行 在本地容器中使用 docker run -it <container:tag> bash 时相同命令的输出是这样的:

#${API_CONTAINER} resolves to gcr.io/<project>/container: I.E. tag gets appended

.../# docker run -it ${API_CONTAINER}latest bash   
root@362737147de4:/app# pwd
/app
root@362737147de4:/app# ls
Dockerfile       dist          files  node_modules       package.json  ssh.bat      stop_forever.bat  test      tsconfig.json
cloudbuild.yaml  environments  log    package-lock.json  src           startApi.sh  swagger.json      test.pdf  tsconfig.test.json
root@362737147de4:/app# 

我对此的想法是,要么推送到注册表实际上是失败的,要么我没有拉正确的,即拉掉一些由云构建构建的 latest 标签在之前的尝试中。

潜在的问题是什么?什么可以解决这个问题?

编辑:在部署中使用不同的标签,在构建过程中使用 --no-cache,并从另一台机器上的注册表中提取后,我的倾向是 GKE 从 GCR 中提取图像时出现问题。有什么办法可以把它放在其他地方,或者了解拉动的情况吗?

编辑 2:

所以是的,我有一个可以共享的 docker 文件,但请注意我继承了它,并且不理解构建它的过程,或者为什么需要一些步骤给其他开发商。 (我绝对有兴趣尽可能多地重构它。

FROM node:8.12.0

RUN mkdir /app
WORKDIR /app

ENV PATH /app/node_modules/.bin:$PATH

RUN apt-get update && apt-get install snmp -y

RUN npm install --unsafe-perm=true
RUN apt-get update \
    && apt-get install -y \
    gconf-service \
    libasound2 \
    libatk1.0-0 \
    libatk-bridge2.0-0 \
    libc6 \
    libcairo2 \
    libcups2 \
    libdbus-1-3 \
    libexpat1 \
    libfontconfig1 \
    libgcc1 \
    libgconf-2-4 \
    libgdk-pixbuf2.0-0 \
    libglib2.0-0 \
    libgtk-3-0 \
    libnspr4 \
    libpango-1.0-0 \
    libpangocairo-1.0-0 \
    libstdc++6 \
    libx11-6 \
    libx11-xcb1 \
    libxcb1 \
    libxcomposite1 \
    libxcursor1 \
    libxdamage1 \
    libxext6 \
    libxfixes3 \
    libxi6 \
    libxrandr2 \
    libxrender1 \
    libxss1 \
    libxtst6 \
    ca-certificates \
    fonts-liberation \
    libappindicator1 \
    libnss3 \
    lsb-release \
    xdg-utils \
    wget

COPY . /app


# Installing puppeteer and chromium for generating PDF of the invoices.


# Install latest chrome dev package and fonts to support major charsets (Chinese, Japanese, Arabic, Hebrew, Thai and a few others)
# Note: this installs the necessary libs to make the bundled version of Chromium that Puppeteer
# installs, work.
RUN apt-get update \
    && apt-get install -y wget gnupg libpam-cracklib \
    && wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - \
    && sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list' \
    && apt-get update \
    && apt-get install -y google-chrome-unstable fonts-ipafont-gothic fonts-wqy-zenhei fonts-thai-tlwg fonts-kacst fonts-freefont-ttf \
      --no-install-recommends \
    && rm -rf /var/lib/apt/lists/*


# Uncomment to skip the chromium download when installing puppeteer. If you do,
# you'll need to launch puppeteer with:
#     browser.launch({executablePath: 'google-chrome-unstable'})
# ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD true

# Install puppeteer so it's available in the container.
RUN npm i puppeteer \
    # Add user so we don't need --no-sandbox.
    # same layer as npm install to keep re-chowned files from using up several hundred MBs more space
    && groupadd -r pptruser && useradd -r -g pptruser -G audio,video pptruser \
    && mkdir -p /home/pptruser/Downloads \
    && chown -R pptruser:pptruser /home/pptruser \
    && chown -R pptruser:pptruser /app/node_modules

#build the api, and move into place.... framework options are limited with the build.
RUN npm i puppeteer kiwi-server-cli && kc build -e prod
RUN rm -Rf ./environments & rm -Rf ./src && cp -R ./dist/prod/* .


# Run everything after as non-privileged user.
# USER pptruser

CMD ["google-chrome-unstable"] # I have tried adding this here as well "&&", "node", "src/server.js"

为了推送图像,我使用了这个命令: docker push gcr.io/<projectid>/api:latest-<version> 并且我使用 cloud auth configure-docker 设置了凭据,这是 yaml 清单的净化版本:

apiVersion: apps/v1
kind: Deployment
metadata:
  annotations:
    kompose.cmd: kompose convert -f ./docker-compose.yml
    kompose.version: 1.21.0 ()
  creationTimestamp: null
  labels:
    io.kompose.service: api
  name: api
spec:
  replicas: 1
  selector:
    matchLabels:
      io.kompose.service: api
  strategy:
    type: Recreate
  template:
    metadata:
      annotations:
        kompose.cmd: kompose convert -f ./docker-compose.yml
        kompose.version: 1.21.0 ()
      creationTimestamp: null
      labels:
        io.kompose.service: api
    spec:
      containers:
      - args:
        - bash
        - -c
        - node src/server.js
        env:
        - name: NODE_ENV
          value: production
        - name: TZ
          value: America/New_York
        image: gcr.io/<projectId>/api:latest-0.0.9
        imagePullPolicy: Always
        name: api
        ports:
        - containerPort: 8087
        resources: {}
        volumeMounts:
        - mountPath: /app
          name: api-claim0
        - mountPath: /files
          name: api-claim1
      restartPolicy: Always
      serviceAccountName: ""
      volumes:
      - name: api-claim0
        persistentVolumeClaim:
          claimName: api-claim0
      - name: api-claim1
        persistentVolumeClaim:
          claimName: api-claim1
status: {}

解决方案来自 docker-compose.yml 文件的原始意图,该文件通过名为 kompose 的工具转换为 kubernetes 清单。原始 docker-compose 文件用于开发,因此具有覆盖以将本地开发环境推送到 运行 容器中。

这是因为在 yml 文件中:

services:
  api:
    build: ./api
    volumes:
      - ./api:/app
      - ./api/files:/files

在 kubernetes 清单上转换为:

      volumeMounts:
      - mountPath: /app
        name: api-claim0
      - mountPath: /files
        name: api-claim1
      volumes:
      - name: api-claim0
        persistentVolumeClaim:
          claimName: api-claim0
      - name: api-claim1
        persistentVolumeClaim:
          claimName: api-claim1

哪个Kubernetes没有提供文件,应用程序基本上被一个空卷覆盖,所以找不到文件。

删除 kubernetes 清单中的指令成功。

提醒我们所有人要注意。

管理图像 [1] 包括在存储库中列出图像、添加标签、删除标签、将图像复制到新存储库以及删除图像。我希望故障排除文档 [2] 可以帮助您解决问题。

[1] https://cloud.google.com/container-registry/docs/managing

[2] https://cloud.google.com/container-registry/docs/troubleshooting