Skip to content

Docker Container Doesn't Build with Muti-Stage and Caching apt Packages Across Images #1597

@aj-stein-nist

Description

@aj-stein-nist

Describe the bug

I had never had this issue before, but while working on multi-stage builds to debug usnistgov/oscal-content#139 and further troubleshoot usnistgov/metaschema#235 to rest, I had not encountered the error below. It is considered bad to use an OS package manager to update and cache and then install in a subsequent stage with a different container. The cache of updated packages for the OS package manager, apt for Debian Linux images in this case, will fail and will act like no package index was pulled at all.

Who is the bug affecting

Developers using docker containers with our current Dockerfile and docker-compose.yml to run local operations with the XSLT toolchain and CI/CD tools.

What is affected by this bug

CI/CD

How do we replicate this issue

  1. Pull down the latest copy of develop
  2. cd /path/to/repo/OSCAL/
  3. cd build/
  4. docker compose build
  5. Review error logs.

You will receive an error message like this.

$ docker compose up -d
[+] Building 2.6s (16/25)                                                                               
 => [internal] load build definition from Dockerfile                                               0.1s
 => => transferring dockerfile: 32B                                                                0.0s
 => [internal] load .dockerignore                                                                  0.1s
 => => transferring context: 2B                                                                    0.0s
 => [internal] load metadata for docker.io/library/ubuntu:22.04                                    0.4s
 => [internal] load metadata for docker.io/library/golang:1.19.4-bullseye                          0.4s
 => [base-environment 1/3] FROM docker.io/library/ubuntu:22.04@sha256:27cb6e6ccef575a4698b66f5de0  0.0s
 => [oscal-hugo-build 1/7] FROM docker.io/library/golang:1.19.4-bullseye@sha256:9554cfef4c535c7fa  0.0s
 => [internal] load build context                                                                  0.1s
 => => transferring context: 285B                                                                  0.0s
 => CACHED [base-environment 2/3] RUN ln -snf /usr/share/zoneinfo/US/Eastern /etc/localtime && ec  0.0s
 => CACHED [base-environment 3/3] RUN apt-get update && apt-get dist-upgrade -y                    0.0s
 => ERROR [oscal-os-dependencies 1/1] RUN apt-get install -y     build-essential git jq libxml2-u  1.6s
 => CACHED [oscal-hugo-build 2/7] RUN mkdir -p /go/src/github.com/usnistgov/OSCAL/build            0.0s
 => CACHED [oscal-hugo-build 3/7] WORKDIR /go/src/github.com/usnistgov/OSCAL/build                 0.0s
 => CACHED [oscal-hugo-build 4/7] ADD tools.go .                                                   0.0s
 => CACHED [oscal-hugo-build 5/7] ADD go.mod .                                                     0.0s
 => CACHED [oscal-hugo-build 6/7] ADD go.sum .                                                     0.0s
 => CANCELED [oscal-hugo-build 7/7] RUN go install -tags "extended" github.com/gohugoio/hugo       1.8s
------
 > [oscal-os-dependencies 1/1] RUN apt-get install -y     build-essential git jq libxml2-utils maven nodejs npm python3-pip unzip wget &&     apt-get clean:
#0 1.401 Reading package lists...
#0 1.438 Building dependency tree...
#0 1.440 Reading state information...
#0 1.445 E: Unable to locate package build-essential
#0 1.445 E: Unable to locate package git
#0 1.445 E: Unable to locate package jq
#0 1.445 E: Unable to locate package libxml2-utils
#0 1.445 E: Unable to locate package maven
#0 1.446 E: Unable to locate package nodejs
#0 1.446 E: Unable to locate package npm
#0 1.446 E: Unable to locate package python3-pip
#0 1.446 E: Unable to locate package unzip
#0 1.446 E: Unable to locate package wget
------
failed to solve: executor failed running [/bin/sh -c apt-get install -y     build-essential git jq libxml2-utils maven nodejs npm python3-pip unzip wget &&     apt-get clean]: exit code: 100

Expected behavior (i.e. solution)

Docker container is successfully built.

Other comments

No response

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions