在 GCP 上的自定义 Docker 映像中创建卷导致错误

Creating volume in custom Docker image on GCP causing error

我有 Angular 个应用 Cypress。我想在 Google Cloud Build.

上创建一个简单的管道配置
images:
  - 'gcr.io/$PROJECT_ID/e2e-tests'

steps:
  # Install node_modules
  - name: node:10.16.3
    entrypoint: npm
    args: ['ci']
    id: install

  # Run linters
  - name: node:10.16.3
    entrypoint: npm
    args: ['run', 'lint']
    id: lint
    waitFor:
      - install

  # Run unit tests
  - name: node:10.16.3
    entrypoint: npm
    args: ['test']
    id: test
    waitFor:
      - lint

  # Run e2e tests
  - name: 'gcr.io/cloud-builders/docker'
    args: [ 'build', '-t', 'gcr.io/$PROJECT_ID/e2e-tests', '-f', 'docker/cypress/Dockerfile', '.' ]
    id: e2e
    waitFor:
      - lint

  # Build app for prod
  - name: node:10.16.3
    entrypoint: npm
    args: ['build']
    id: build
    waitFor:
      - test
      - e2e

不幸的是我不能使用内置的 npm 图像,因为 Cypress 需要安装一些额外的库。这就是为什么我开始建立自己的形象。

# THIS ONE IS WORKING

FROM node:lts

RUN apt-get update && \
  apt-get install -y \
    libgtk2.0-0 \
    libnotify-dev \
    libgconf-2-4 \
    libnss3 \
    libxss1 \
    libasound2 \
    xvfb

ENV PATH /app/node_modules/.bin:$PATH
ENV CI=1

WORKDIR /app
COPY . /app

RUN npm ci
RUN npm run e2e:ci

当我将应用程序复制到容器中时它起作用了。但是我必须再次安装依赖项,所以我决定将 COPY 替换为 VOLUME 以加快整个过程。

# THIS ONE GETS AN ERROR LISTED BELOW

FROM node:lts

RUN apt-get update && \
  apt-get install -y \
    libgtk2.0-0 \
    libnotify-dev \
    libgconf-2-4 \
    libnss3 \
    libxss1 \
    libasound2 \
    xvfb

ENV PATH /app/node_modules/.bin:$PATH
ENV CI=1

VOLUME . /app

WORKDIR /app

RUN npm run e2e:ci

GCB 日志(最新优先):

OCI runtime create failed: container_linux.go:345: starting container process caused "process_linux.go:430: container init caused \"apply apparmor profile: apparmor failed to apply profile: open /proc/self/attr/exec: no such file or directory\"": unknown
---> Running in be2a7992ad86
Step 7/7 : RUN npm run e2e:ci
---> 4fc9a0a86172
Removing intermediate container 53ee0d15063f
---> Running in 53ee0d15063f
Step 6/7 : WORKDIR /app
---> dd7298b536a0
Removing intermediate container 7f15a02f79e2
---> Running in 7f15a02f79e2
Step 5/7 : VOLUME . /app
---> 63124861eb3d
Removing intermediate container 28231f3bbf16
---> Running in 28231f3bbf16
Step 4/7 : ENV CI=1
---> a2563c01781f
Removing intermediate container 1579023b86b1
---> Running in 1579023b86b1
Step 3/7 : ENV PATH /app/node_modules/.bin:$PATH
---> d765db9e3ddf
Removing intermediate container a0ac5fd5da98
Processing triggers for libc-bin (2.24-11+deb9u4) ...
Setting up notification-daemon (3.20.0-1+b1) ...
Setting up libgtk-3-bin (3.22.11-1) ...
Setting up libgtk-3-0:amd64 (3.22.11-1) ...
Setting up librest-0.7-0:amd64 (0.8.0-2) ...
...

我做错了什么?

当您使用命令 运行 时,您在容器的 BUILD 期间启动了一个命令。就像您执行的 apt-get:您 运行 安装软件包。

构建自定义 Cloud Builder 时,无法在容器构建时设置卷。因此,您不必 运行 命令。

将最后的RUN替换为ENTRYPOINT,定义容器执行时的默认命令为运行。

然后,当你使用你的容器时,不要忘记指定体积