Stop the Wait: Fixing Docker's 'Sending Build Context' Hang

beginner๐Ÿณ Docker2026-07-22| Docker Engine 20.10+, Docker Desktop on macOS/Windows/Linux

Error Message

Sending build context to Docker daemon [Size > 100MB]...
#docker#devops#performance

The Problem: Why your build hangs before it even startsYou hit enter on docker build -t my-app . and wait. And wait some more. Instead of seeing your steps execute, the terminal hangs on a single, frustrating line:

Sending build context to Docker daemon  2.45GB

If that number is in the gigabytes, your build will be painfully slow. It might even crash the Docker daemon entirely. This happens because Docker uses a client-server architecture. When you trigger a build, the client bundles every file in your current directory and ships it to the daemon. This transfer happens before Docker even glances at your Dockerfile instructions.

Common culprits for context bloat- Local Dependencies: Folders like node_modules (often 500MB+), venv, or target.- Version Control: A .git directory that has ballooned over years of commits.- Media and Data: Forgotten database dumps (.sql), large CSV files, or high-res assets.- Build Artifacts: Old binaries, log files, or dist folders from previous runs.## Step 1: Find the heavy hittersStop guessing which files are the problem. You need to identify exactly what is eating up your space. Run these commands in your project root to see folder sizes:

On Linux or macOS:

du -sh * | sort -h

On Windows (PowerShell):

ls | Select-Object Name, @{Name="Size(MB)";Expression={$_.Length / 1MB}} | Sort-Object "Size(MB)" -Descending

Look for any directory that doesn't strictly need to be inside your final container image. If node_modules shows up as 800MB, that is your primary target.

Step 2: The Fix โ€” Create a .dockerignore fileThe most effective solution is creating a .dockerignore file in your project root. It works just like .gitignore. It tells the Docker client to leave specific files behind rather than shipping them to the daemon.

Create the file and add these standard offenders immediately:

# Ignore dependencies (install these inside the Dockerfile instead) 
node_modules/
venv/
.venv/

# Ignore source control
.git
.gitignore

# Ignore IDE and OS junk
.idea/
.vscode/
.DS_Store

# Ignore build outputs and logs
dist/
build/
*.log
*.sql
*.zip

Step 3: Switch to Docker BuildKitModern Docker versions include BuildKit, a much smarter build engine. Unlike the legacy builder, BuildKit only transfers the files actually requested by your COPY or ADD commands. This can turn a 2GB transfer into a 2MB one.

To use BuildKit for a single build, set the environment variable in your terminal:

DOCKER_BUILDKIT=1 docker build -t my-app .

For a permanent fix on Linux, edit your /etc/docker/daemon.json to include:

{
  "features": {
    "buildkit": true
  }
}

Step 4: Audit your COPY commandsEven with a .dockerignore, a "lazy" Dockerfile can slow you down. Avoid copying your entire project at the start of the file. This ruins layer caching and forces unnecessary data transfers.

The slow way:

COPY . . 
RUN npm install

The professional way:

# Copy only the manifest first
COPY package.json package-lock.json ./
RUN npm install

# Now copy the rest of the source code
COPY ./src ./src

The Result: Instant BuildsRun your build again and check the first line of output. If you see something like this:

Sending build context to Docker daemon  142kB

The size has dropped from gigabytes to kilobytes. The "Sending build context" phase should now be instant. Your build will jump straight to the first instruction in your Dockerfile, saving you minutes of idle time every single day.

Related Error Notes