.DockerIgnore WSL2 --Not Ignoring


My .dockerignore file does not seem to ‘ignore’ directories.

In the build logs, the .dockerignore file is being loaded. => [internal] load .dockerignore
That said, the only .dockerignore command that works is to ignore everything with ‘*’

In my .dockerignore in the project root, I’ve tried

What am I missing?

Docker Desktop v4.15.0
Windows 10 WSL 2
:white_check_mark: Use the WSL 2 based Engine
:white_check_mark: Use Docker Compose V2

running in WSL2 Ubuntu Terminal:
docker system prune -a
docker-compose up --build

Much appreciation in advance

  1. Can you show a directory tree to show what you want to ignore?
  2. What is your build context in the compose file?

In your build context a simple


should ignore the whole directory. If you want to ignore

Please use code blocks for commands and codes otherwise your post could be altered by forum and it is hard to notice your shared commands even without that

I’d like to ignore the ‘archive’

  • archive
  • modules_dir
  • main.py
  • DockerFile
  • .dockerignore
  • .gitignore

First 4 lines of DockerFile:

# syntax = docker/dockerfile:1
FROM python:3.9.9-slim-buster

ENV PIP_CACHE_DIR=/var/cache/buildkit/pip

in the .dockerignore file running in pycharm pro windows…running wsl2

Thanks :slight_smile:

Okay, but please, don’t ignore the end of my post :slight_smile:

You can see how your code was changed right? I guess the first line should have been a comment not a title.

Regarding the question, your dockerignore seems right. I tested it on macOS (so not on Windows) with docker run and also with docker compose.

Well, this first 4 lines doesn’t seem relevant, but I haven’t asked for a Dockerfile so no problem.

If you want to simplify, please don’t change the name of the directories unless the original name is secret. :slight_smile:

How did you realize it didn’t work? Do you have a copy command that copies everything from the project root?

How did you realize it didn’t work?

In the running docker container, the ‘archive’ directory is still there.

There are so many strange happenings with WSL2 and Windows 10.
Perhaps, someone on that system has an idea

Can anyone give confirmation that .dockerignore works on WSL2 Windows?
Or, is there a more verbose log file that docker produces–how it is parsing .dockerignore?


It is possible that I still don’t understand your environment correctly. I tried it on my Windows and it worked.

Please, try this:

Folder structure


Content of Dockerfile:

FROM alpine
COPY . /app

Content of .dockerignore


The content of the txt files doesn’t matter, just create empty txt files.

Run this command to build an image:

docker build . -t localhost/test

Run this command to test the result:

docker run --rm localhost/test find /app

You should get this:


If you get this, we know the issue does not always happen. If you have different result (the order of the lines doesn’t matter) then something is different on our hosts, or there is something wrong with the encoding of the files.

That works :slight_smile: The only difference -I’m using a docker-compose.yml file for my project
Mine looks looks like this

version: "3.9"
    build: .
    image: 123456789.thing.domain.com/repo:
      - "8889:8889"
      - .:/app

is there a default yml file you would use for the debug?

I think I got it. The bind mount was overwriting dockerignore
I changed the ‘volume’ settings from:

  - .:/app


  - ./vol:/app/vol

Wait, the bind mount should not affect the build.
Did that really solved everything?


Okay, I edited my edited comment… I thought I was wrong first, but I understand now the build was right but you mounted the files to the same folder where you copied the files during the build. Thanks for sharing the solution. I really should have asked for the compose file in the beginning :slight_smile:

1 Like

this worked for me, thanks.