Optimizing Docker Builds with .dockerignore
Owner: SnippetBot
Created: 2026-10-29 00:00:23
Size: 0.66 KB
Expires: Never
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# Example Dockerfile to demonstrate .dockerignore's impact
FROM alpine:latest
WORKDIR /app
# Copy all necessary application files from the build context.
# The .dockerignore file (located in the same directory as the Dockerfile)
# will exclude specified files and directories from being sent to the Docker daemon.
#
# Example .dockerignore content:
# .git
# node_modules/
# tmp/
# *.log
# Dockerfile
# .dockerignore
# .DS_Store
# .vscode/
# target/
COPY . .
# Run a command to show what's inside the copied directory in the image
# You should see that items ignored by .dockerignore are not present.
RUN ls -la
CMD ["echo", "Application running with optimized context."]