@@ -98,7 +98,7 @@ download of base images and dependencies.
9898``` dockerfile
9999# syntax=docker/dockerfile:1
100100FROM ubuntu:24.04
101- RUN apt-get -y update && apt-get install -y python
101+ RUN apt-get -y update && apt-get install -y --no-install-recommends python3
102102```
103103
104104Also consider [ pinning base image versions] ( #pin-base-image-versions ) .
@@ -165,7 +165,7 @@ review. Adding a space before a backslash (`\`) helps as well.
165165Here’s an example from the [ buildpack-deps image] ( https://github.com/docker-library/buildpack-deps ) :
166166
167167``` dockerfile
168- RUN apt-get update && apt-get install -y \
168+ RUN apt-get update && apt-get install -y --no-install-recommends \
169169 bzr \
170170 cvs \
171171 git \
@@ -322,7 +322,7 @@ For example, you can chain commands with the `&&` operator, and use
322322escape characters to break long commands into multiple lines.
323323
324324``` dockerfile
325- RUN apt-get update && apt-get install -y \
325+ RUN apt-get update && apt-get install -y --no-install-recommends \
326326 package-bar \
327327 package-baz \
328328 package-foo
@@ -337,7 +337,7 @@ with a pipeline operator:
337337``` dockerfile
338338RUN <<EOF
339339apt-get update
340- apt-get install -y \
340+ apt-get install -y --no-install-recommends \
341341 package-bar \
342342 package-baz \
343343 package-foo
@@ -356,7 +356,7 @@ Always combine `RUN apt-get update` with `apt-get install` in the same `RUN`
356356statement. For example:
357357
358358``` dockerfile
359- RUN apt-get update && apt-get install -y \
359+ RUN apt-get update && apt-get install -y --no-install-recommends \
360360 package-bar \
361361 package-baz \
362362 package-foo
@@ -370,7 +370,7 @@ subsequent `apt-get install` instructions to fail. For example, this issue will
370370
371371FROM ubuntu:22.04
372372RUN apt-get update
373- RUN apt-get install -y curl
373+ RUN apt-get install -y --no-install-recommends curl
374374```
375375
376376After building the image, all layers are in the Docker cache. Suppose you later
@@ -381,7 +381,7 @@ modify `apt-get install` by adding an extra package as shown in the following Do
381381
382382FROM ubuntu:22.04
383383RUN apt-get update
384- RUN apt-get install -y curl nginx
384+ RUN apt-get install -y --no-install-recommends curl nginx
385385```
386386
387387Docker sees the initial and modified instructions as identical and reuses the
@@ -390,14 +390,14 @@ because the build uses the cached version. Because the `apt-get update` isn't
390390run, your build can potentially get an outdated version of the ` curl ` and
391391` nginx ` packages.
392392
393- Using ` RUN apt-get update && apt-get install -y ` ensures your Dockerfile
393+ Using ` RUN apt-get update && apt-get install -y --no-install-recommends ` ensures your Dockerfile
394394installs the latest package versions with no further coding or manual
395395intervention. This technique is known as cache busting. You can also achieve
396396cache busting by specifying a package version. This is known as version pinning.
397397For example:
398398
399399``` dockerfile
400- RUN apt-get update && apt-get install -y \
400+ RUN apt-get update && apt-get install -y --no-install-recommends \
401401 package-bar \
402402 package-baz \
403403 package-foo=1.3.*
@@ -411,7 +411,7 @@ Below is a well-formed `RUN` instruction that demonstrates all the `apt-get`
411411recommendations.
412412
413413``` dockerfile
414- RUN apt-get update && apt-get install -y \
414+ RUN apt-get update && apt-get install -y --no-install-recommends \
415415 aufs-tools \
416416 automake \
417417 build-essential \
0 commit comments