Skip to content

Instantly share code, notes, and snippets.

@tsangwpx
Last active February 26, 2024 06:20
Show Gist options
  • Save tsangwpx/fd3c5c2b9aac53d9d0964cf3dc91b2ed to your computer and use it in GitHub Desktop.
Save tsangwpx/fd3c5c2b9aac53d9d0964cf3dc91b2ed to your computer and use it in GitHub Desktop.
apt SRV records and debian-based docker image

apt/apt-get commands may use SRV record to find nearby APT service. 1

However, offical Debian/Ubuntu images cannot utilize such functonality unless /etc/services file is present.

This means APT will download packages from deb.debian.org / archive.ubuntu.com as usual. 🤣

This also means local APT (cache/proxy) servers is bypassed and the build process may be slowed down if the bandwidth is limited.

Workaround

  • apt-get install -y netbase in the very beginning but this still down the package from remote.
  • RUN apt-get update && apt-get install -y netbase and let docker cache this RUN command.
    Great when often rebuilt. 🛠️
  • Acquire::http::Proxy but only useful in private use (proxy server usually behind firewall?) .
  • Modify /etc/apt/sources.list or /etc/hosts, but cons as above.
  • Modify A/CNAME record in local DNS service and point to local APT service. This is another reliability/maintenance story.

Details

When APT query SRV, it asks the service name of port 80 with getservbyport_r(), which use /etc/services, which shipped in netbase. http is not an easy answer there. Therefore, everything works as usual. 🤣

keywords for search engines

apt, apt-get, apt cache, apt proxy, srv records, dns, apt-cacher-ng, netbase, /etc/services

@woshikid
Copy link

Only one entry of /etc/services is needed to use apt with SRV in Debian.
echo "http 80/tcp" > /etc/services will do the trick instead of install netbase.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment