docker-compose版本和docker build不会在复制文件时共享层现金

时间:2019-08-09 07:56:04

标签: docker docker-compose dockerfile

当我使用docker-compose build构建多阶段docker构建时,docker层兑现不会转移到docker build .命令中

在下面提供的日志中,您会看到WORKDIR命令使用docker层兑现,但是COPY忽略了它并创建了一个新的哈希。 (文件完全没有更改)。

当我仅使用 docker builddocker-compose构建时,不会发生这种情况。 这是构建的日志:

T02429:app$ docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
node                10                  9b9d314e0a86        7 hours ago         904MB
T02429:app$ docker-compose build test
Building test
Step 1/6 : FROM node:10 as base
 ---> 9b9d314e0a86
Step 2/6 : WORKDIR /usr/src/app
 ---> Running in fc2d962f4fd0
Removing intermediate container fc2d962f4fd0
 ---> 362c0b907170
Step 3/6 : COPY package.json ./
 ---> 7457757e0221
Step 4/6 : COPY yarn.lock ./
 ---> 8bb824d2d7cd
Step 5/6 : COPY jest.config.js ./
 ---> 584c78a1cce8
Step 6/6 : COPY src src
 ---> 8d7aac67a142

Successfully built 8d7aac67a142
Successfully tagged test_image:latest
T02429:app$ docker build -t full_build .
Sending build context to Docker daemon    255kB
Step 1/12 : FROM node:10 as base
 ---> 9b9d314e0a86
Step 2/12 : WORKDIR /usr/src/app
 ---> Using cache
 ---> 362c0b907170
Step 3/12 : COPY package.json ./
 ---> 48e89caded31
Step 4/12 : COPY yarn.lock ./
 ---> 58c942524315
Step 5/12 : COPY jest.config.js ./
 ---> 02b7f45d1d90
Step 6/12 : COPY src src
 ---> 708fe2761b39
Step 7/12 : FROM node:10 as prod
 ---> 9b9d314e0a86
Step 8/12 : WORKDIR /usr/src/app
 ---> Using cache
 ---> 362c0b907170
Step 9/12 : COPY --from=base /usr/src/app/package.json package.json
 ---> 542eacbc1285
Step 10/12 : COPY --from=base /usr/src/app/src src
 ---> c40cbe92f9ec
Step 11/12 : EXPOSE 3000
 ---> Running in 66473d8427c7
Removing intermediate container 66473d8427c7
 ---> f5b1b1deafab
Step 12/12 : CMD [ "echo", "hello world" ]
 ---> Running in a8c4609e7159
Removing intermediate container a8c4609e7159
 ---> 863470696544
Successfully built 863470696544
Successfully tagged full_build:latest

这是我的docker文件:

# The instructions for the first stage
FROM node:10 as base
WORKDIR /usr/src/app

COPY package.json ./
COPY yarn.lock ./
COPY jest.config.js ./
COPY src src

# The instructions for second stage
FROM node:10 as prod
WORKDIR /usr/src/app

COPY --from=base /usr/src/app/package.json package.json
COPY --from=base /usr/src/app/src src

EXPOSE 3000
CMD [ "echo", "hello world" ]

这是我的docker-compose.yml

version: '3.7'

services:
  web:
    image: web_image:latest
    build:
      context: .
      target: prod
  test:
    image: test_image:latest
    build:
      context: .
      target: base
    environment:
      - CI=true
    command: echo Hello

0 个答案:

没有答案