There is a shorter and easier method to write your .dockerignore :

vendor/bundle/**/*
vendor/bundle
Answer from sebthemonster on Stack Overflow
🌐
Markbirbeck
markbirbeck.com › 2018 › 12 › 07 › getting-control-of-your-dockerignore-files
Getting Control Of Your .dockerignore Files | Mark Birbeck’s Blog
December 7, 2018 - This post shows how to control .dockerignore by indicating which files we want to include rather than those we want to exclude. For a while now I’ve been trying to come up with an easy way to exclude unecessary files from my Docker images. Obviously I want to keep secrets out, and I want to prevent any unused directories from being transferred to the Docker daemon when building–they slow down the build as well as increase the size of the resulting images.
🌐
Docker
docs.docker.com › manuals › docker build › build context
Build context | Docker Docs
The .dockerignore file is a newline-separated list of patterns similar to the file globs of Unix shells. Leading and trailing slashes in ignore patterns are disregarded. The following patterns all exclude a file or directory named bar in the ...
Discussions

docker - How can I exclude a sub-directory with a .dockerignore file - Stack Overflow
I want to exclude a sub-directory using a .dockerignore file, but I don't know what the syntax should be, and there are no examples anywhere. I have a sub-directory vendor/bundle. I've put vendor/ More on stackoverflow.com
🌐 stackoverflow.com
Docker ignore file used in sub directories

That depends on what your docker build command looks like. If you perform a docker build -f app/Dockerfile . from the parent directory where the .dockerignore file is then it would include the .dockerignore but if you are in either app or server and run docker build ., it wouldn't be included as .dockerignore isn't in the build context.

More on reddit.com
🌐 r/docker
2
3
July 7, 2017
docker - Ignore directories with .dockerignore or volume? - Stack Overflow
I'm not linking the volume to a directory in the host, or any other container. Its just a volume known to the web-server container only. I am also reading that there is a way via .dockerignore to exclude the directory when I initially build the image for the container. More on stackoverflow.com
🌐 stackoverflow.com
docker - Dockerignore: Ignore everything except a file and the Dockerfile - Stack Overflow
You can combine both approaches by putting the dockerfile in a subdirectory and use .dockerignore. According to the docs, it is good to do so anyways 2020-09-23T08:39:11.103Z+00:00 ... Docker's documentation: In most cases, it’s best to start with an empty directory as context and keep your ... More on stackoverflow.com
🌐 stackoverflow.com
🌐
LinkedIn
linkedin.com › pulse › securing-docker-builds-comprehensive-guide-usage-best-ilyas-ou-sbaa
Securing Docker Builds: A Comprehensive Guide to .dockerignore Usage and Best Practices
July 17, 2023 - The .dockerignore file is placed in the same directory as the Dockerfile and is used during the build process to determine which files and directories should be included or excluded from the Docker image.
🌐
Medium
medium.com › @LihauTan › took-me-hours-to-realise-why-docker-build-ignores-my-dockerignore-and-this-is-what-ive-learned-2f87c770ea9c
Took me hours to realise why docker build ignores my .dockerignore, and this is what I’ve learned | by Tan Li Hau | Medium
November 26, 2017 - Before the docker CLI sends the context to the docker daemon, it looks for a file named .dockerignore in the root directory of the context. If this file exists, the CLI modifies the context to exclude files and directories that match patterns in it.
🌐
GeeksforGeeks
geeksforgeeks.org › devops › how-to-use-a-dockerignore-file
How to Use a .dockerignore File? - GeeksforGeeks
April 8, 2024 - Let's take a look at a practical example of using a .dockerignore file. Step 1: Create a directory containing a dockerfile where you specify the instructions and a folder that you want to ignore (say ignore-this).
🌐
CloudBees
cloudbees.com › blog › leveraging-the-dockerignore-file-to-create-smaller-images
Leveraging the dockerignore File to Create Smaller Images
The file itself is a simple text file that contains a list of glob patterns for files and directories to exclude from the final build image. By leveraging the .dockerignore file, we can exclude files and directories we do not need within our final image.
Find elsewhere
🌐
Medium
medium.com › @bounouh.fedi › mastering-the-dockerignore-file-boosting-docker-build-efficiency-398719f4a0e1
Mastering the .dockerignore File: Boosting Docker Build Efficiency | by Fedi Bounouh | Medium
November 9, 2024 - This includes not only source code but also unnecessary files such as logs, temporary files, and build artifacts. The .dockerignore file is a simple text file you place in your project root to exclude files or directories from the build context.
🌐
Mrugesh Mohapatra
hn.mrugesh.dev › how-to-use-a-dockerignore-file-a-comprehensive-guide-with-examples
How to Use a .dockerignore File: A Comprehensive Guide with Examples • Mrugesh Mohapatra
May 25, 2023 - When you run docker build ., Docker will ignore the node_modules directory, potentially saving you time and space. Creating a .dockerignore file is as simple as creating any other file.
🌐
Codefresh
codefresh.io › home › blog › do not ignore .dockerignore (it’s expensive and potentially dangerous)
Do not ignore .dockerignore (it's expensive and potentially dangerous) | Codefresh
March 13, 2025 - If you don’t manage the build ... build context, we can see how this is done. The .dockerignore file is similar to gitignore file, used by the git tool....
🌐
CyberPanel
cyberpanel.net › blog › dockerignore-file
Mastering the .dockerignore file for Optimized Docker builds
July 17, 2025 - ... The dockerfile ignore refers to controlling what files from your project should be considered when the Dockerfile is processed. This is achieved by using both .dockerignore and COPY/ADD commands effectively in your Dockerfile.
🌐
TutorialsPoint
tutorialspoint.com › how-to-ignore-files-in-docker
How to ignore files in Docker?
The ".dockerignore" should be created where your Dockerfile is present otherwise it won't work. Use the below commands to create and exclude various types of files. ... We have created a directory structure to use in explaining all these methods.
🌐
Docker Community
forums.docker.com › docker desktop
.DockerIgnore WSL2 --Not Ignoring - Docker Desktop - Docker Community Forums
December 13, 2022 - Hello. 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, ...
🌐
TechRepublic
techrepublic.com › home › what are .dockerignore files, and why you should use them?
What are .dockerignore files, and why you should use them? - TechRepublic
November 7, 2022 - The .dockerignore file is very similar to the .gitignore file in that it allows you to specify a list of files or directories that Docker is to ignore during the build process. This can come in really handy in certain instances.
🌐
OneUptime
oneuptime.com › home › blog › how to use docker ignore files
How to Use Docker Ignore Files
January 25, 2026 - # .dockerignore # Comments start with # # Blank lines are ignored # Ignore specific file secret.key # Ignore all files with extension *.log *.tmp # Ignore entire directories node_modules/ .git/ # Ignore files starting with pattern temp-* # Ignore files in any subdirectory **/*.md # But include specific file (exception) !README.md
🌐
Cratecode
cratecode.com › info › docker ignore usage
Docker Ignore Usage | Cratecode
May 13, 2023 - A .dockerignore file is a plain text file that specifies which files and directories should be excluded from the Docker build context. It's similar to how a .gitignore file works for Git repositories.