Review apt use in Dockerfile automation

Use apt-get and apt-cache for automated commands.

Description

Use apt-get to install packages in a Dockerfile and apt-cache to look up package information. The apt interface is designed for an interactive terminal.

Potential impact

Changes to apt output or behavior between releases can break build scripts.

Remediation

Refresh the index and install packages in the same RUN, using -y for installation confirmation. If the build needs a particular package version, pin it explicitly.

Examples

Only the second example refreshes the package index before installing curl on Ubuntu. Add cache cleanup to the same step if needed.

Before

dockerfile
FROM ubuntu:24.04

RUN apt install -y curl

After

dockerfile
FROM ubuntu:24.04

RUN apt-get update \
    && apt-get install -y curl

References