标签: docker-layer

如何在 Azure DevOps 中启用 Docker 层缓存

我正在运行以下 yaml 脚本来构建 docker 镜像并推送到 kubernetes 集群,但同时我想在构建 yaml 脚本时在 azure DevOps 中启用 docker 层缓存。请解释一下如何启用或如何添加azure devops 中的任务来做到这一点。

亚姆:

# Starter pipeline
# Start with a minimal pipeline that you can customize to build and deploy your code.
# Add steps that build, run tests, deploy, and more:
# https://aka.ms/yaml

trigger:
- master

pool:
  vmImage: 'ubuntu-latest'

variables:
  tag: 'web'
  DockerImageName: 'boiyaa/google-cloud-sdk-nodejs'


steps:
- task: Docker@2
  inputs:
    command: 'build'
    Dockerfile: '**/Dockerfile'
    tags: 'web'
  
- script: |
    echo ${GCLOUD_SERVICE_KEY_STAGING} > ${HOME}/gcp-key.json
               gcloud auth activate-service-account …
Run Code Online (Sandbox Code Playgroud)

azure-devops docker-layer

7
推荐指数
3
解决办法
7649
查看次数

Docker 忽略多阶段构建的文件

我需要在第一阶段排除 Docker COPY 中的文件,但在第二阶段的另一个 COPY 中使用它,因为它会破坏 Docker 层缓存。

我的文件夹结构如下:

src/
public/
.env
package.json
nginx.conf
Run Code Online (Sandbox Code Playgroud)

我的 Dockerfile 如下所示:

FROM node:14 as builder                   # line-1
WORKDIR /app                              # line-2
COPY . /app                               # line-3 nginx.conf is copied but not needed
RUN yarn && yarn build                    # line-4

FROM nginx:1.21.1                         # line-5
WORKDIR /app                              # line-6
COPY --from=builder /app/build /app/build # line-7
COPY nginx.conf /app                      # line-8 nginx.conf is copied

CMD nginx -c /app/nginx.conf              # line-9
Run Code Online (Sandbox Code Playgroud)

当我更改nginx.confdocker 层缓存时,由于第三行,缓存变得无效。

我无法使用,.dockerignore因为它会在两个阶段都忽略它。 …

docker dockerfile docker-image docker-copy docker-layer

5
推荐指数
0
解决办法
1806
查看次数