Skip to content

dockerignore prevents build from working #6615

@utdrmac

Description

@utdrmac

Issue Description

This is the dockerignore posing issues for use with buildah. If I remove this file, buildah works, but if the file is present, something doesn't work correctly and the files are not copied into the building container. Relevant Dockerfile

gitlab runner output:

build1:
  stage: build
  image: quay.io/containers/buildah:latest
  script:
    - echo "=== stage:build script ==="
    - ls -la
    - buildah build -f Dockerfile -t "$IMAGE_NAME"
    - buildah images
    - buildah push "$IMAGE_NAME"




$ echo "=== stage:build script ==="
=== stage:build script ===
$ ls -la
total 116
drwxrwxrwx. 12 root root 16384 Dec 25 03:36 .
drwxrwxrwx.  4 root root    56 Dec 25 03:36 ..
drwxrwxrwx.  2 root root    54 Dec 25 03:36 .devcontainer
-rw-rw-rw-.  1 root root   383 Dec 25 03:36 .dockerignore
drwxrwxrwx.  6 root root   113 Dec 25 03:36 .git
drwxrwxrwx.  5 root root    72 Dec 25 03:36 .github
-rw-rw-rw-.  1 root root   460 Dec 25 03:36 .gitignore
-rw-rw-rw-.  1 root root   832 Dec 25 03:36 .gitlab-ci.yml
-rw-rw-rw-.  1 root root   930 Dec 25 03:36 .golangci.yml
-rw-rw-rw-.  1 root root  6290 Dec 25 03:36 CONTRIBUTING.md
-rw-rw-rw-.  1 root root  1232 Dec 25 03:36 Dockerfile
-rw-rw-rw-.  1 root root 11357 Dec 25 03:36 LICENSE
-rw-rw-rw-.  1 root root 11054 Dec 25 03:36 Makefile
-rw-rw-rw-.  1 root root   663 Dec 25 03:36 PROJECT
-rw-rw-rw-.  1 root root  5930 Dec 25 03:36 README.md
-rw-rw-rw-.  1 root root  3364 Dec 25 03:36 SUPPORT.md
drwxrwxrwx.  3 root root    22 Dec 25 03:36 api
drwxrwxrwx.  2 root root    21 Dec 25 03:36 cmd
drwxrwxrwx.  9 root root   114 Dec 25 03:36 config
drwxrwxrwx.  2 root root    32 Dec 25 03:36 docs
-rw-rw-rw-.  1 root root  4631 Dec 25 03:36 go.mod
-rw-rw-rw-.  1 root root 23636 Dec 25 03:36 go.sum
drwxrwxrwx.  2 root root    32 Dec 25 03:36 hack
drwxrwxrwx.  4 root root    38 Dec 25 03:36 internal
drwxrwxrwx.  4 root root    30 Dec 25 03:36 test
$ buildah build -f Dockerfile -t "$IMAGE_NAME"
[1/2] STEP 1/9: FROM golang:1.24 AS builder
Resolved "golang" as an alias (/etc/containers/registries.conf.d/000-shortnames.conf)
Trying to pull docker.io/library/golang:1.24...
Getting image source signatures
Copying blob sha256:76da54420e1edd91a760c3248b46ee9cade4a7969f9da7bcff9b40eee7d95788
Copying blob sha256:2981f7e8980b9f4b6605026e1c5f99b4971ebba15f626e46904554de09f324f4
Copying blob sha256:58f2d358b447d091790c5ef0943550bbcf57bac46c4b8bfcfc3e6dacf4cb7969
Copying blob sha256:2f9dc3e96e7f673873071f3abef7cbb5fb77c69508e799dbe503bf1e316168d8
Copying blob sha256:b22766554d6bfa95c7325b00ee002f2705a7b8605908c3eb43dbe729c412422c
Copying blob sha256:94cc3e02e353c0efcfdaf6be736e5d50dbde521e32a7ec4b0a8f8ce54558c2c2
Copying blob sha256:4f4fb700ef54461cfa02571ae0db9a0dc1e0cdb5577484a6d75e68dc38e8acc1
Copying config sha256:ec07d1d940ae89674b89151998a5e760ace7e5a376f1536c98b8b075ca51d2cf
Writing manifest to image destination
[1/2] STEP 2/9: ARG TARGETOS
[1/2] STEP 3/9: ARG TARGETARCH
[1/2] STEP 4/9: WORKDIR /workspace
[1/2] STEP 5/9: COPY go.mod go.mod
[1/2] STEP 6/9: COPY go.sum go.sum
[1/2] STEP 7/9: RUN go mod download
[1/2] STEP 8/9: COPY . .
[1/2] STEP 9/9: RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o manager cmd/main.go
package cmd/main.go is not in std (/usr/local/go/src/cmd/main.go)
subprocess exited with status 1
subprocess exited with status 1
Error: building at STEP "RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o manager cmd/main.go": exit status 1

Steps to reproduce the issue

Steps to reproduce the issue

  1. Attempt to build container with buildah which uses a .dockerignore file
  2. Observe that build fails
  3. Remove .dockerignore and repeat attempt
  4. Observe that build succeeds

Describe the results you received

Builds with buildah containing a .dockerignore file will fail for some reason

Describe the results you expected

Builds to work correctly

buildah version output

`  image: quay.io/containers/buildah:latest`

buildah info output

gitlab runner in K8S

Provide your storage.conf

File is not used

Upstream Latest Release

Yes

Additional environment details

Additional environment details

Additional information

Additional information like issue happens only occasionally or issue happens with a particular architecture or on a particular setting

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/bugCategorizes issue or PR as related to a bug.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions