apt-cacher-ng
make a dockerfile
$ cat Dockerfile
FROM debian:buster
RUN apt-get update \
&& apt-get install -y --no-install-recommends apt-cacher-ng \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
VOLUME ["/var/cache/apt-cacher-ng"]
EXPOSE 3142
CMD chmod 777 /var/cache/apt-cacher-ng \
&& /etc/init.d/apt-cacher-ng start \
&& tail -f /var/log/apt-cacher-ng/*
build an image
$ sudo docker build -t apt-cacher-ng:buster . | tee build.log
$ sudo docker tag apt-cacher-ng:buster apt-cacher-ng:latest
run a container
$ sudo docker run --rm -d -p 3142:3142 -v /mnt/apt-cacher-ng:/var/cache/apt-cacher-ng apt-cacher-ng:latest
test the address and port
$ curl 192.168.xxx.xxx:3142
how to use the cache server
specify it in a config file
$ cat << END | sudo tee /etc/apt/apt.conf.d/01proxy
> Acquire::http::Proxy "http://192.168.xxx.xxx:3142/";
> END
specify it in command line
$ http_proxy=http://192.168.xxx.xxx:3142/ sudo -E apt-get install xxxx
or
$ sudo su -
# http_proxy=http://192.168.xxx.xxx:3142/ apt-get install xxxx
for docker build
$ sudo docker build --build-arg http_proxy=http://192.168.xxx.xxx:3142/ -t imagename:tagname . | tee build.log