How to create a private mirror of apt repositories


As an example, we will take a configuration that will download and maintain the relevance of apt repositories for ubuntu 24.04.

To create your own mirror of apt repositories, you only need 2 components:

  • nginx web server or similar
  • script for downloading and maintaining the relevance of repositories
  • to isolate the software being installed, we will use docker, although this is not necessary
Let’s start with creating a root folder for configuration:
mkdir -p /var/apt-mirror/config && mkdir -p /var/apt-mirror/packages && cd /var/apt-mirror && 
Download script for syncing
git clone https://github.com/Denrox/mirror-rsync.git ./ && rm -rf .git README.md && chmod +x mirror-rsync.sh
Create a docker-compose.yml
services:
  apt-mirror:
    image: nginx:1.27.3-alpine3.20-perl
    container_name: apt-mirror
    restart: always
    networks:
      - frontend
    volumes:
      - ./config/apt-mirror.conf:/etc/nginx/conf.d/apt-mirror.conf
      - ./packages:/var/www/apt-mirror
./config/apt-mirror.conf
server {
  listen 80;
  server_name mirror.intra;

  root /var/www/apt-mirror/archive.ubuntu.com;

  location / {
    autoindex on;
  }
}
Run initial download for apt registry
cd /var/docker/apt-mirror && ./mirror-rsync.sh

After this, the last command can be added to the directory. After the steps we have gone through, the configured mirror can be used to install packages in Ubuntu 24.04.

To do this, you need to replace in /etc/apt/sources.list.d/ubuntu.sources

URIs: http://mirror.intra/ubuntu/