Useful Snippets


This blog is used to collect useful snippets related to Linux, PHP, MySQL and more. Feel free to post comments with improvements or questions!

Are your smart devices spying on you? Make better purchasing choices and find products that respect your privacy at

RSS Latest posts from my personal blog

Most viewed posts

Subscribe to RSS feed

Identify which files are included in the Docker build context

Stanislav KhromovStanislav Khromov

If you have ever run docker build or docker-compose up just to have Docker stuck on “Building” for minutes? This might be because you are including too many files in your Docker build context.

Normally Docker will send along files that might be unnecessary for your build process such as node_modules, vendor or even the .git folder. This can be remedied using the .dockerignore file.

But what if you’ve added files to .dockerignore and your build is still slow? In that case you can use this excellent script from GitHub user sgdan that will show you all of the files you are sending to your build context:


# Based on BMitch's answer from:

# Note: will create and delete temporary file ""

# 1. Copy to project folder where image is being built
# 2. Run script
# 3. You should see list of files in build context
# 4. If unwanted files in context, adjust .dockerignore file and go back to step 2

cat <<EOF >
FROM busybox
COPY . /build-context
WORKDIR /build-context
CMD find .

docker build -f -t build-context .
docker run --rm -it build-context


Create the file as, run chmod +x and then ./ and you will see all the included context files, like this:

[+] Building 1.9s (8/8) FINISHED                                                                                                         
 => [internal] load build definition from 
 => => transferring dockerfile: 125B
 => [internal] load .dockerignore 

More good reading on .dockerignore files.

Web Developer at Aftonbladet (Schibsted Media Group)
Any opinions on this blog are my own and do not reflect the views of my employer.
Twitter Profile
Visit my other blog

Comments 0
There are currently no comments.