Keywords: Docker | Ubuntu | APT cache cleanup
Abstract: This paper investigates the common issue of Ubuntu repository signature verification failures during Docker builds, characterized by errors such as 'At least one invalid signature was encountered' and 'The repository is not signed'. By identifying the root cause—insufficient disk space leading to APT cache corruption—it presents best-practice solutions including cleaning APT cache with sudo apt clean, and freeing system resources using Docker commands like docker system prune, docker image prune, and docker container prune. The discussion highlights the importance of avoiding insecure workarounds like --allow-unauthenticated and emphasizes container security and system maintenance practices.
Problem Description and Context
When building Docker containers based on Ubuntu images, developers often encounter failures in the APT package manager. Specifically, running apt-get update results in multiple repository signature verification errors, for example:
Err:2 http://archive.ubuntu.com/ubuntu bionic InRelease
At least one invalid signature was encountered.
W: GPG error: http://archive.ubuntu.com/ubuntu bionic InRelease: At least one invalid signature was encountered.
E: The repository 'http://archive.ubuntu.com/ubuntu bionic InRelease' is not signed.These errors indicate that APT cannot verify the GPG signatures of Ubuntu's official repositories, typically occurring in Dockerfiles using FROM ubuntu:latest or specific versions like ubuntu:18.04. The issue not only affects the base image but also disrupts subsequent package installations, causing build failures.
Root Cause Analysis
Through in-depth investigation, the core issue is identified as insufficient disk space. When the root partition is full, APT's caching mechanism may fail to store or verify GPG key files properly. In Docker environments, frequent image builds and package downloads can accumulate temporary data, consuming limited space resources. This explains why the error appears across different Ubuntu versions (e.g., bionic, eoan), as the problem is unrelated to image content but rather the state of the host or container filesystem.
From a technical perspective, APT relies on GPG signatures to ensure the integrity and authenticity of software packages. If cache directories (e.g., /var/cache/apt/) become corrupted due to space constraints, the signature verification process fails, triggering "invalid signature" errors. This differs from network issues or repository misconfigurations, which typically manifest as connection timeouts or 404 errors.
Solutions and Implementation Steps
Based on best practices, resolving this problem should start with cleaning the APT cache, avoiding insecure workarounds like --allow-unauthenticated, which bypasses signature verification and introduces security risks. Here are detailed steps:
- Clean APT Cache: Before the
RUNinstruction in the Dockerfile or after a build failure, executesudo apt clean. This removes downloaded package files from/var/cache/apt/archives/, freeing space and resetting the cache state. For example, in a Dockerfile, this can be optimized as:
This structure ensures automatic cache cleaning and retry on installation failure.FROM ubuntu:latest RUN apt-get update && apt-get install -y g++ llvm lcov || (apt-get clean && apt-get update && apt-get install -y g++ llvm lcov) - Free Docker System Resources: Complementing with insights from other answers, use Docker's built-in tools to manage disk space:
docker system df: View Docker disk usage to identify large components like "Build Cache".docker system prune --force: Non-interactively clean unused images, containers, and networks to quickly free space. Supported since Docker API v1.25+.docker image prune --forceanddocker container prune --force: Target cleanup of images and containers to reduce residual data.docker volume prune --force: If using volume storage, clean up unattached volumes.
Security Considerations and Best Practices
When addressing such issues, developers should prioritize security. Using options like --allow-unauthenticated or --allow-insecure-repositories disables APT's signature verification, potentially allowing malicious or compromised packages, which violates container security principles. In contrast, cleaning the cache maintains the integrity of the verification mechanism, adhering to the principle of least privilege.
Furthermore, it is recommended to integrate regular cleanup steps into CI/CD pipelines, such as automatically running docker system prune after builds, to maintain system health. Monitoring disk usage (e.g., via df -h) can also provide early warnings of space problems.
Conclusion and Extensions
This paper analyzes the common cause of Ubuntu repository signature verification failures in Docker builds—insufficient disk space—and provides solutions based on apt clean and Docker pruning commands. By comparing different methods, it emphasizes the importance of maintaining cache integrity and system security. In practice, developers should adapt strategies to specific environments, e.g., adding automated cleanup tasks in resource-constrained servers. Although a minor issue, it reflects deeper challenges in resource management and security practices within containerized development, warranting ongoing optimization in DevOps workflows.