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
Use the WSL 2 based Engine
Use Docker Compose V2
running in WSL2 Ubuntu Terminal:
docker system prune -a
docker-compose up --build
Much appreciation in advance
Can you show a directory tree to show what you want to ignore?
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
The Docker forum is using
Discourse, which supports several ways to format your posts:
Markdown; see commonmark.org/help for an interactive tutorial
A small selection of HTML
Any combination of the above
Blank lines for formatting and readability
Quite often you’ll need an empty line above specific formatting to make it work.
You also need to type blank lines to create proper paragraphs; just pressing Return once and then typing a new block of text right below a previous block only…
I’d like to ignore the ‘archive’
First 4 lines of DockerFile:
# syntax = docker/dockerfile:1
RUN mkdir -p $PIP_CACHE_DIR
in the .dockerignore file running in pycharm pro windows…running wsl2
Okay, but please, don’t ignore the end of my post
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.
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:
Content of Dockerfile:
COPY . /app
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.
The only difference -I’m using a docker-compose.yml file for my project
Mine looks looks like this
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:
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
this worked for me, thanks.