Failed to get layer during multistage builds in Docker

I am encountering an intermittent error when using GitLab runners to build Docker images, specifically during multistage builds. This issue occurs sporadically; however, when it manifests on a particular machine, subsequent builds on that same machine consistently fail, indicating a persistent issue with that specific machine environment. Interestingly, the same build job may succeed on a different machine.

To address this, we have found that completely wiping the Docker directory serves as a temporary workaround.

We have also attempted to implement this workaround (adding RUN true between COPY commands as discussed in this GitHub issue), but it did not resolve the problem.

Build ends with this error:

#25 [base 4/7] RUN rm -rf /flyway/jre
#25 CACHED
#26 [base 5/7] RUN ln -s /flyway/flyway /usr/local/bin
#26 CACHED
#27 [base 6/7] COPY ./docker/testcontainer-postgres-xxx/onInit/flyway-migrate.sh /usr/local/bin
#27 CACHED
#28 [final 3/3] RUN echo ${PIPELINE_ID} > /tmp/pipeline_id
#28 CACHED
#29 exporting to image
#29 exporting layers done
#29 preparing layers for inline cache done
#29 writing image sha256:b9c9b7b5436bfab4b7f94d73f9501c2ac2cf26d68ab63feedcbe4c5b86061cfb done
#29 ERROR: failed to get layer sha256:4572d629188142b6cf001bec82a4f44f795854b40d7432942a77a5308d58254e: layer does not exist

We have found this error in runners syslog:

Mar 21 06:15:44 gitlab-runner-3 dockerd[1650152]: time="2024-03-21T06:15:44.732808293Z" level=info msg="Layer sha256:a9fb5fd507b30c7a01deba587053acc920cc115435ce5fae405438c88b48a60e cleaned up"

Execution command:

docker build
      --build-arg BUILDKIT_INLINE_CACHE=1
      --cache-from $TEST_CONTAINER_POSTGRES_ADATA_TAG_BASE:develop
      --cache-from $TEST_CONTAINER_POSTGRES_ADATA_COMMIT_REF_SLUG
      --build-arg POSTGRES_IMAGE_NAME=$POSTGRES_IMAGE_NAME
      --build-arg FLYWAY_BASE_IMAGE=$DOCKER_IMAGE_TAG
      --build-arg type=adata
      -t $TEST_CONTAINER_POSTGRES_ADATA_COMMIT_REF_SLUG
      -f ./docker/testcontainer-postgres-xxx/Dockerfile .

Dockerfile:

ARG POSTGRES_IMAGE_NAME=registry.xxx.com/xxx/postgres/postgres-xxx:16-2-xxx-1-2-0
ARG FLYWAY_BASE_IMAGE=develop
ARG type=app-schema

# hax so we can define tag via variable
FROM registry.xxx.com/xxx/core/flyway-base:$FLYWAY_BASE_IMAGE as flyway-base

FROM $POSTGRES_IMAGE_NAME AS base

ENV POSTGRES_USER postgres
ENV POSTGRES_PASSWORD passwd

ENV FLYWAY_OUT_OF_ORDER=true
ENV FLYWAY_BASELINE_ON_MIGRATE=true
ENV FLYWAY_PLACEHOLDER_REPLACEMENT=false
ENV FLYWAY_CONNECT_RETRIES=120
# Number of flyways that are checked for repeatability in each schema, starting with the newest one
ENV REPEATABILITY_CHECK_SIZE=6
# Default password for every type
ENV FLYWAY_PASSWORD passwd

# default flyway connection config
ENV DB_NAME xxx
ENV DB_USER xxx



## Get flyway script
# java version must match the one used by flyway cmd
RUN apt-get update && apt-get install -y --no-install-recommends openjdk-17-jre
COPY --from=flyway-base /flyway /flyway
# do not include jre provided in flyway. Installed JRE will be used to simplify java setup
RUN rm -rf /flyway/jre
RUN ln -s /flyway/flyway /usr/local/bin
########################

COPY ./docker/testcontainer-postgres-xxx/onInit/flyway-migrate.sh /usr/local/bin
RUN ["chmod", "+x", "/usr/local/bin/flyway-migrate.sh"]

######### Stages based on defined type #########
FROM base AS app-schema
ARG DB_SCHEMAS="app admin quartz translations"
# Regular Flyways
COPY ./app/app-db/src/main/resources/db/app/ ./docker-entrypoint-initdb.d/app/
COPY ./app/app-db/src/main/resources/db/translations/ ./docker-entrypoint-initdb.d/translations/
COPY ./app/app-db/src/main/resources/db/admin/ ./docker-entrypoint-initdb.d/admin/
COPY ./app/app-db/src/main/resources/db/qrtz/ ./docker-entrypoint-initdb.d/quartz/

# Extra flyways for IT
COPY ./app/app-db/src/main/resources/db/it-app/ ./docker-entrypoint-initdb.d/app/

# used for verifying flyway scripts in gitlab pipeline test stage and as source of configured DB for MR namespaces
FROM base AS app-data
ARG DB_SCHEMAS="app admin quartz translations app_data admin_data app_seed"
# Regular Flyways
COPY ./app/app-db/src/main/resources/db/app/ ./docker-entrypoint-initdb.d/app/
COPY ./app/app-db/src/main/resources/db/translations/ ./docker-entrypoint-initdb.d/translations/
COPY ./app/app-db/src/main/resources/db/admin/ ./docker-entrypoint-initdb.d/admin/
COPY ./app/app-db/src/main/resources/db/qrtz/ ./docker-entrypoint-initdb.d/quartz/
COPY ./app/app-db/src/test/resources/db/app_data/ ./docker-entrypoint-initdb.d/app_data/
COPY ./docker/flyway-seed-xxx-app/sql/ ./docker-entrypoint-initdb.d/app_seed/
COPY ./app/app-db/src/test/resources/db/admin_data/ ./docker-entrypoint-initdb.d/admin_data/
...

New contributor

martva is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật