Skip to content

Commit

Permalink
Update Dockerfile template to match best practices
Browse files Browse the repository at this point in the history
Changes:

- Remove `-y` flag from `apt-get update`, as it
  has no effect on that command.
- Use `--no-install-recommends` flag to avoid
  installing unnecessary dependencies.
- Use more general wildcard to remove apt package
  list cache.
- Remove `apt-get clean` command, as official
  Debian and Ubuntu images run it automatically.
- Update example in the documentation to match
  the changes.

Reference:

- https://docs.docker.com/build/building/best-practices/#apt-get
  • Loading branch information
rhcarvalho committed Dec 20, 2024
1 parent e0fa893 commit 806964d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
10 changes: 5 additions & 5 deletions guides/deployment/releases.md
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,8 @@ ARG RUNNER_IMAGE="debian:${DEBIAN_VERSION}"
FROM ${BUILDER_IMAGE} AS builder

# install build dependencies
RUN apt-get update -y && apt-get install -y build-essential git \
&& apt-get clean && rm -f /var/lib/apt/lists/*_*
RUN apt-get update && apt-get install -y --no-install-recommends build-essential git \
&& rm -rf /var/lib/apt/lists/*

# prepare build dir
WORKDIR /app
Expand Down Expand Up @@ -227,9 +227,9 @@ RUN mix release
# the compiled release and other runtime necessities
FROM ${RUNNER_IMAGE}

RUN apt-get update -y && \
apt-get install -y libstdc++6 openssl libncurses5 locales ca-certificates \
&& apt-get clean && rm -f /var/lib/apt/lists/*_*
RUN apt-get update && \
apt-get install -y --no-install-recommends libstdc++6 openssl libncurses5 locales ca-certificates \
&& rm -rf /var/lib/apt/lists/*

# Set the locale
RUN sed -i '/en_US.UTF-8/s/^# //g' /etc/locale.gen && locale-gen
Expand Down
10 changes: 5 additions & 5 deletions priv/templates/phx.gen.release/Dockerfile.eex
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ ARG RUNNER_IMAGE="debian:${DEBIAN_VERSION}"
FROM ${BUILDER_IMAGE} AS builder

# install build dependencies
RUN apt-get update -y && apt-get install -y build-essential git \
&& apt-get clean && rm -f /var/lib/apt/lists/*_*
RUN apt-get update && apt-get install -y --no-install-recommends build-essential git \
&& rm -rf /var/lib/apt/lists/*

# prepare build dir
WORKDIR /app
Expand Down Expand Up @@ -69,9 +69,9 @@ RUN mix release
# the compiled release and other runtime necessities
FROM ${RUNNER_IMAGE}

RUN apt-get update -y && \
apt-get install -y libstdc++6 openssl libncurses5 locales ca-certificates \
&& apt-get clean && rm -f /var/lib/apt/lists/*_*
RUN apt-get update && \
apt-get install -y --no-install-recommends libstdc++6 openssl libncurses5 locales ca-certificates \
&& rm -rf /var/lib/apt/lists/*

# Set the locale
RUN sed -i '/en_US.UTF-8/s/^# //g' /etc/locale.gen && locale-gen
Expand Down

0 comments on commit 806964d

Please sign in to comment.