Keywords: Docker | apt-get update | HTTPS driver
Abstract: This article provides an in-depth analysis of the 'apt-get update' non-zero code 100 error encountered during Dockerfile builds, particularly focusing on driver missing issues caused by HTTPS sources. By examining the root cause, it offers a solution involving the installation of the apt-transport-https package and discusses best practices for Docker image construction, including layer optimization and cache management. With step-by-step code examples, it guides readers on modifying Dockerfiles to resolve similar issues, supplemented by additional tips such as system cleanup.
Problem Background and Error Analysis
During the Docker image build process, a user attempted to create a custom image from the Ubuntu 14.04.4 base image, with the Dockerfile containing multiple software source configurations and GPG key imports. However, when executing the apt-get update command, the build failed with a return code of 100. The specific error message was: E: The method driver /usr/lib/apt/methods/https could not be found. This indicates that the system lacks the necessary driver to handle HTTPS protocols.
Root Cause Investigation
The core issue arises from the addition of a software source using the HTTPS protocol in the Dockerfile: deb [arch=amd64] https://apt-mo.trafficmanager.net/repos/azurecore/ trusty main. In the default Ubuntu 14.04.4 base image, the apt-transport-https package is not installed by default. This package provides APT with the capability to handle HTTPS connections. Consequently, when apt-get update attempts to access the HTTPS source, the system cannot locate the corresponding driver method, leading to command failure.
Solution and Code Implementation
To resolve this issue, the apt-transport-https package must be installed before adding the HTTPS source. A modified Dockerfile example is as follows:
FROM ubuntu:14.04.4
RUN apt-get update && apt-get install -y apt-transport-https
RUN echo 'deb http://private-repo-1.hortonworks.com/HDP/ubuntu14/2.x/updates/2.4.2.0 HDP main' >> /etc/apt/sources.list.d/HDP.list
RUN echo 'deb http://private-repo-1.hortonworks.com/HDP-UTILS-1.1.0.20/repos/ubuntu14 HDP-UTILS main' >> /etc/apt/sources.list.d/HDP.list
RUN echo 'deb [arch=amd64] https://apt-mo.trafficmanager.net/repos/azurecore/ trusty main' >> /etc/apt/sources.list.d/azure-public-trusty.list
RUN gpg --keyserver pgp.mit.edu --recv-keys B9733A7A07513CAD
RUN gpg -a --export 07513CAD | apt-key add -
RUN gpg --keyserver pgp.mit.edu --recv-keys B02C46DF417A0893
RUN gpg -a --export 417A0893 | apt-key add -
RUN apt-get updateIn this modification, the command apt-get update && apt-get install -y apt-transport-https is executed first to ensure the system has the capability to handle HTTPS sources. This step uses the && operator to combine two commands into a single RUN instruction, which helps reduce the number of Docker image layers and optimize build efficiency. After installation, subsequent operations for adding software sources and updating will no longer encounter the HTTPS driver missing issue.
Best Practices and Optimization Suggestions
When writing Dockerfiles, it is advisable to combine multiple RUN instructions to minimize image layers, such as appropriately grouping software source configurations and key imports. Additionally, regularly using docker system prune to clean up unused images and containers can free up disk space and avoid cache-related problems, as mentioned in other answers as supplementary advice. For production environments, consider using more modern Ubuntu versions, as 14.04 has reached end-of-life for mainstream support and may pose security risks.
Conclusion
By installing the apt-transport-https package, the issue of apt-get update failure due to HTTPS sources in Docker builds can be effectively resolved. This approach is not only applicable to this case but can also be extended to other similar scenarios. Developers should focus on layer optimization and system maintenance in Dockerfiles to improve build success rates and efficiency.