APT-Cache-ng is a Life Saver for Situation which you do not want to Give Internet to Your Ubuntu Servers for Updating Packages
apt cacher is a caching proxy for Debian based distributions that creates a local cache of Debian-based mirrors as well as other Linux distributions. This means that whenever a package is pulled from the official repositories, an APT cache server caches them such that if any other local machine would want to install the same package, it just pulls it from the local caching server. This helps eliminates the bottlenecks of slow internet connections.
Apt-Cacher NG has been designed from scratch as a replacement for apt-cacher, but with a focus on maximizing throughput with low system resource requirements. It can also be used as replacement for apt-proxy and approx with no need to modify clients’ sources.list files.
In This Article we want to implement APT-Cacher NG
Configuration
Install with Package
1- Easily you can install APT-Cacher-ng by run Following Command :
apt-get install apt-cacher-ng
2- Enable APT cacher in Startup by doing :
systemctl enable apt-cacher-ng
Install with Docker
1- Update apt repository and install APT-Transport which allows us to add new repository easily
sudo apt-get update
sudo apt-get install \
apt-transport-https \
ca-certificates \
curl \
gnupg \
lsb-release
2- Add Official Docker ‘s GPG key
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
3- Add Docker Repository
echo \
"deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
4- Install Docker-Ce
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io
5- Install Docker-compose for Bringing Apt-cacher-ng Container up
sudo chmod +x /usr/local/bin/docker-compose
6- Make a docker-compose.yml and Paste following Parameter :
---
version: '3'
services:
apt-cacher-ng:
image: sameersbn/apt-cacher-ng
container_name: apt-cacher-ng
ports:
- "3142:3142"
volumes:
- apt-cacher-ng:/var/cache/apt-cacher-ng
restart: always
volumes:
apt-cacher-ng:
7- Bring up your Docker-cmpose by doing :
docker-compose up -d
8- You can Get access to APT cacher by entering your http://Machine IP:3172 (192.168.110.200:3172)
8–1 As you can see we can get access to Statistics (how much package cached) by clicking on Statistics and report and Configuration Page
Client Side Config
We have 2 option for configuring Client To Give Packages From APT-Cacher-NG
1- Send All APT Repository Requests to the Proxy Section By Creating /etc/apt/apt.conf.d/02proxy File and Put Following Section To IT :
`Acquire::http { Proxy "http://192.168.110.200:3142"; };
192.168.110.200 is our apt-cacher-ng ip
`
OR
2- Appending your APT Cacher URL:PORT to Your APT Repository Like:
deb http://192.168.110.200:3142/ftp.debian.org/debian stable main contrib non-free
deb-src http://192.168.110.200:3142/ftp.debian.org/debian stable mrnickfetratmain contrib non-free
deb http://192.168.110..200:3142/HTTPS///get.docker.com/ubuntu docker main
Conclusion
You Can Cache Packages , Speed UP Downloading Packages and Also Not Accessing Your Servers To the Internet By Simply Using APT Cacher-NG