Use apt-cacher to speed up container builds
Pull the apt-cacher-ng Docker Image
docker pull sameersbn/apt-cacher-ng
Run the apt-cacher-ng Container
Start the container and expose port `3142`
docker run -d --name apt-cacher-ng \
-p 3142:3142 \
sameersbn/apt-cacher-ng
Modify the Dockerfile to Use the Cache
In all Dockerfiles, set up APT to use the proxy provided by `apt-cacher-ng`.
XX:
RUN echo 'Acquire::http::Proxy "http://host.docker.internal:3142";' \
> /etc/apt/apt.conf.d/01proxy && \
apt-get update && apt-get install --no-install-recommends --assume-yes \
unzip curl ca-certificates default-jdk && \
apt-get clean && rm -rf /var/lib/apt/lists/*
If you are building on the same machine, use host.docker.internal (on
macOS/Windows) or the host's IP address on Linux.