How to fix dpkg-preconfigure: unable to re-open stdin: No such file or directory in APT

APTBEGINNERLOWUpdated Dec 29, 2025ยท 205 views

This warning appears when running apt-get in non-interactive environments like Docker containers or CI/CD pipelines. While it doesn't prevent package installation, it indicates that debconf cannot access a terminal for interactive configuration. Setting DEBIAN_FRONTEND=noninteractive or redirecting stdin resolves the issue.

Quick fix

Fixes dpkg-preconfigure: unable to re-open stdin: No such file or directory

FROM ubuntu:22.04

# Set noninteractive frontend
ENV DEBIAN_FRONTEND=noninteractive

# Now apt-get runs without trying to prompt
RUN apt-get update && apt-get install -y \
    curl \
    git \
    wget

# Optional: reset for subsequent stages
ENV DEBIAN_FRONTEND=dialog
  1. Set DEBIAN_FRONTEND=noninteractive in Dockerfile
  2. Use APT_LISTCHANGES_FRONTEND=none for additional safety
  3. Set locale variables to avoid additional warnings
  4. Comment out or remove DPkg preconfigure line
apt โ€” error
FROM ubuntu:22.04
# Set noninteractive frontend
ENV DEBIAN_FRONTEND=noninteractive
# Now apt-get runs without trying to prompt
RUN apt-get update && apt-get install -y \
curl \
git \
wget
# Optional: reset for subsequent stages
ENV DEBIAN_FRONTEND=dialog
dpkg-preconfigure: unable to re-open stdin: No such file or directory

What this error means

The "dpkg-preconfigure: unable to re-open stdin: No such file or directory" error occurs when the Debian package configuration tool (debconf) tries to interact with the terminal but finds no valid input stream. During package installation, dpkg-preconfigure attempts to ask configuration questions using debconf's interactive frontends (Dialog, Readline, Teletype) in sequence. When running in a container, automated environment, or with redirected stdin, none of these frontends can function properly. Debconf falls through all available frontends and ultimately fails when trying to re-open stdin. In most cases, packages still install successfully despite this warning, but it clutters logs and indicates improper environment configuration. The error is most common in Docker builds, Vagrant provisioning, CI/CD pipelines (GitHub Actions, GitLab CI), and automated server provisioning tools.

Typical symptoms

  • Docker build shows 'dpkg-preconfigure: unable to re-open stdin: No such file or directory' warning
  • Vagrant provisioning displays 'debconf: unable to initialize frontend' followed by preconfigure warning
  • apt-get commands in CI/CD pipelines print multiple fallback messages before failing on stdin
  • Build log shows: 'debconf: falling back to frontend: Dialog', 'falling back to frontend: Readline', then preconfigure error
  • Package installation completes despite the warning appearing

Common causes

  1. DEBIAN_FRONTEND environment variable not set to 'noninteractive' in container/automation
  2. Running apt-get with stdin redirected (e.g., < /dev/null) in interactive environments
  3. Using docker exec or similar without -i (interactive) flag to allocate a pseudo-terminal
  4. Debconf preconfiguration script (/etc/apt/apt.conf.d/70debconf) tries to interact without a terminal
  5. Running apt-get in a shell that doesn't provide a controlling terminal
  6. Using older Debian/Ubuntu base images where debconf interaction wasn't properly disabled

How to fix "dpkg-preconfigure: unable to re-open stdin: No such file or directory"

1Set DEBIAN_FRONTEND=noninteractive in Dockerfile

The most reliable solution is to set the environment variable before running apt commands. This tells debconf to use the noninteractive frontend, which skips all prompts and uses default answers:

dockerfile
FROM ubuntu:22.04

# Set noninteractive frontend
ENV DEBIAN_FRONTEND=noninteractive

# Now apt-get runs without trying to prompt
RUN apt-get update && apt-get install -y \
    curl \
    git \
    wget

# Optional: reset for subsequent stages
ENV DEBIAN_FRONTEND=dialog

The ENV instruction works for all RUN commands that follow it in the same image stage. If using multi-stage builds, set it in each stage that needs it.

Important: Use ENV (persistent) rather than ARG (build-time only). Some older Docker versions don't properly pass ARG to RUN commands.

2Use APT_LISTCHANGES_FRONTEND=none for additional safety

Some debconf-related tools try to show changelogs. Disable them as well:

dockerfile
FROM ubuntu:22.04

ENV DEBIAN_FRONTEND=noninteractive
ENV APT_LISTCHANGES_FRONTEND=none

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

This prevents apt-listchanges from trying to interact during installation.

3Set locale variables to avoid additional warnings

Optionally configure locale settings to avoid perl warnings and ensure consistent encoding:

dockerfile
FROM ubuntu:22.04

ENV DEBIAN_FRONTEND=noninteractive
ENV LANGUAGE=en_US.UTF-8 \
    LANG=en_US.UTF-8 \
    LC_ALL=en_US.UTF-8

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

This is optional but recommended for cleaner build logs.

4Comment out or remove DPkg preconfigure line

For existing containers or systems that already have the error, you can disable preconfiguration by modifying the debconf configuration:

bash
# Comment out the DPkg preconfigure line
sudo ex +"%s@DPkg@//DPkg" -cwq /etc/apt/apt.conf.d/70debconf

# Or simply remove the file if you don't need debconf at all
sudo rm /etc/apt/apt.conf.d/70debconf

Then reconfigure debconf to use noninteractive mode:

bash
sudo dpkg-reconfigure debconf -f noninteractive -p critical

This is a container-level fix for running systems, but in Docker it's better to set ENV variables.

5Avoid redirecting stdin when it's not necessary

If you're running apt in interactive mode (not Docker), be careful with stdin redirection:

bash
# BAD - redirects stdin, causes preconfigure to fail
apt-get install -y package < /dev/null

# GOOD - no stdin redirection, relies on -y flag
apt-get install -y package

# BETTER - set environment variable
DEBIAN_FRONTEND=noninteractive apt-get install -y package

The -y flag automatically answers 'yes' to prompts, but debconf still attempts initialization before seeing the flag.

6Redirect stderr if you only need to suppress the warning

If the error doesn't block your build and you just want to silence it, redirect stderr:

bash
apt-get update 2>/dev/null
apt-get install -y package 2>/dev/null

Or in Dockerfile:

dockerfile
RUN apt-get update 2>/dev/null && \
    apt-get install -y curl 2>/dev/null

Note: This just hides the warning; it's not a proper fix. The recommended approach is to set DEBIAN_FRONTEND.

Advanced notes

Why does this happen in Docker? Docker containers have no controlling terminal (TTY) by default. When dpkg-preconfigure runs, it tries to open /dev/tty to access stdin, but this device doesn't exist. It then falls back through Dialog (requires tty), Readline (requires tty), and Teletype frontends before giving up.

Difference between preconfigure and reconfigure: dpkg-preconfigure runs BEFORE package installation (asking configuration questions upfront), while dpkg-reconfigure runs AFTER (modifying existing package configuration). Both require a terminal unless DEBIAN_FRONTEND is set to noninteractive.

Multi-stage builds: If using multi-stage builds, set DEBIAN_FRONTEND in each stage that runs apt commands:

dockerfile
FROM ubuntu:22.04 AS builder
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update && apt-get install -y build-essential

FROM ubuntu:22.04 AS runtime
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update && apt-get install -y libcurl4
COPY --from=builder /app /app

Using ARG vs ENV: Some guides suggest using ARG before FROM and passing it with --build-arg. This approach is less reliable. Prefer ENV for clarity and consistency.

Performance impact: Using DEBIAN_FRONTEND=noninteractive may slightly speed up builds since debconf doesn't try to initialize interactive frontends. In Docker, this is usually negligible.

Why it's "just a warning": Packages still install because debconf gives up and apt-get continues. The package's install scripts run successfully; only the configuration interaction is skipped. In most cases, this is exactly what you want in automation.

Frequently asked questions

What does "dpkg-preconfigure: unable to re-open stdin: No such file or directory" mean?
The "dpkg-preconfigure: unable to re-open stdin: No such file or directory" error occurs when the Debian package configuration tool (debconf) tries to interact with the terminal but finds no valid input stream. During package installation, dpkg-preconfigure attempts to ask configuration questions using debconf's interactive frontends (Dialog, Readline, Teletype) in sequence. When running in a container, automated environment, or with redirected stdin, none of these frontends can function properly.
How do I fix "dpkg-preconfigure: unable to re-open stdin: No such file or directory"?
This warning appears when running apt-get in non-interactive environments like Docker containers or CI/CD pipelines. While it doesn't prevent package installation, it indicates that debconf cannot access a terminal for interactive configuration. Setting DEBIAN_FRONTEND=noninteractive or redirecting stdin resolves the issue.
What causes "dpkg-preconfigure: unable to re-open stdin: No such file or directory"?
DEBIAN_FRONTEND environment variable not set to 'noninteractive' in container/automation Running apt-get with stdin redirected (e.g., < /dev/null) in interactive environments Using docker exec or similar without -i (interactive) flag to allocate a pseudo-terminal
Is the "dpkg-preconfigure: unable to re-open stdin: No such file or directory" error serious?
It is a low-severity error โ€” more of a blocker than a risk. The steps above resolve it.

Official resources & further reading