billions-sundown-65740
03/09/2026, 12:53 PMdocker_image target in Pants the COPY command in a Dockerfile appears to bypass .dockerignore logic (COPY folder folder) if the files are matched by
files(
sources=[
"folder/**/*"]
)
in BUILD. All files are materialized in the build sandbox and subsequently copied into the image, even if they are listed in .dockerignore. While I can use ! exclusions in the BUILD file, should not pants honors the .dockerignore file automatically to be more compliant with the Docker/Podman?happy-kitchen-89482
03/11/2026, 2:56 AMhappy-kitchen-89482
03/11/2026, 2:58 AMcurved-television-6568
03/11/2026, 6:20 AM.dockerignore
Then when pants runs docker build using the sandbox as build context, it (i.e. docker) will respect any .dockerignore in the sandbox meaning, you'll need to make sure that pants materializes it there, by including .dockerignore in some valid target source type that is a dependency of your docker_imagecurved-television-6568
03/11/2026, 6:22 AM.dockerignore files when deciding what goes into the build context/sandbox.curved-television-6568
03/11/2026, 6:24 AMbillions-sundown-65740
03/18/2026, 7:45 AM.dockerignore files by default into the sandbox is the best and simplest approach for now. Maybe adding a parameter (feature flag) to pants.toml in order to activate it (and adding a deprecation warning that in future releases the behaviour will change) would be the safest approach to prevent unexpected behaviours when updating the pants version.