docker / docker/buildx

Buildkit ignores .dockerignore in Git repository

Open
#2,353 6 comments 4 reactions 1 assignee View on GitHub

@dvdksn is already working on this.

Since Aug 1, 2024.

Dominant language
Go
Stars
4.5k
Forks
682
Avg merge
2d 14h
Merged PRs (30d)
29

Description

When using docker build with a Git repo as build context and DOCKER_BUILDKIT=1 the .dockerignore contents in the Git repo gets ignored and the files/directories get copied in the Docker image.
When DOCKER_BUILDKIT env is not set, the ignored files/directories are correctly excluded and can't be found in the Docker image.

Steps to reproduce the issue:

  1. export DOCKER_BUILDKIT=1
  2. docker build https://github.com/PHOENIX-MEDIA/buildkit-test.git
  3. docker run -ti --rm <image> sh
  4. ls -la /var/www/html/
    The files in https://github.com/PHOENIX-MEDIA/buildkit-test/blob/master/.dockerignore shouldn't be in the html folder.

You can repeat the steps with a clone of the repository on your local machine:

  1. git clone https://github.com/PHOENIX-MEDIA/buildkit-test.git .
  2. docker build .
  3. docker run -ti --rm <image> sh
  4. ls -la /var/www/html/
    The folder only contains the copy.me file, which is the expected result according to the .dockerignore contents.

I'm using Docker version 19.03.13, build 4484c46d9d on Centos7.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.