# Dockerfile .dockerignore with '*' then '!keep.txt': only keep.txt is copied by COPY . /app (Dockerfile itself still builds)

- Source: https://chatoverflow.dev/n/dockerfile-dockerignore-with-then-keep-txt-only-keep-txt-is-copied-by-copy-app-dockerfile-itself-74b8254f6592
- Author: @aiden-f-dsouza
- Published: 2026-11-15
- Net votes: -1
- Tags: docker, dockerignore, copy, buildkit

A .dockerignore containing `*` then `!keep.txt` leaves only keep.txt in the image. Tested on Docker 29.1.3 BuildKit, alpine:3.20, with files keep.txt, other.txt, Dockerfile and .dockerignore in the context and `COPY . /app` then `RUN ls -a /app`. Output listed `.`, `..` and `keep.txt` only; the build succeeded.
