Build and run your own apt-offline docker container for updates and installs without Internet
For Start up of Ubuntu 22.04 offline repo:
Create the local volume: mkdir /home/user/path/apt-mirror
Build the Image: docker build -t apt-offline-repo .
Run the Image: docker run -d -p 8080:80 -v /home/user/path/apt-mirror:/var/spool/apt-mirror --name apt-repo apt-offline-repo
For Start up of Ubuntu 24.04 offline repo:
Create the local volume: mkdir /home/user/path/apt-mirror-24.04
Build Image: docker build -t apt-offline-repo-24.04 .
Run Image: docker run -d -p 8081:80 -v /home/user/path/apt-mirror-24.04:/var/spool/apt-mirror --name apt-repo-24.04 apt-offline-repo-24.04
Set up local machine to use offline Repo:
For Ubuntu 22.04 deb [trusted=yes] http://localhost:8080/archive.ubuntu.com/ubuntu jammy main restricted universe multiverse deb [trusted=yes] http://localhost:8080/archive.ubuntu.com/ubuntu jammy-updates main restricted universe multiverse deb [trusted=yes] http://localhost:8080/security.ubuntu.com/ubuntu jammy-security main restricted universe multiverse
For Ubuntu 24.04
Edit /etc/apt/sources.list on clients:
deb [trusted=yes] http://localhost:8081/archive.ubuntu.com/ubuntu noble main restricted universe multiverse deb [trusted=yes] http://localhost:8081/archive.ubuntu.com/ubuntu noble-updates main restricted universe multiverse deb [trusted=yes] http://localhost:8081/security.ubuntu.com/ubuntu noble-security main restricted universe multiverse
Checking apt-mirror Status and Progress
To monitor the apt-mirror process in your container, use logs, process checks, and file inspections. Since apt-mirror runs in the background (via the CMD loop), these methods help track progress without interrupting it.
-
Check Container Logs (Easiest for Real-Time Progress)
Command: docker logs -f apt-repo-24.04 (replace with your container name, e.g., apt-repo for 22.04). What It Shows: Live output from apt-mirror, including download progress (e.g., "Downloading... 50%"), errors, or completion messages. Press Ctrl+C to stop following. Tip: For initial runs, this displays mirroring steps. If logs are empty, mirroring hasn't started yet.
-
Check Running Processes Inside the Container
Exec into Container: docker exec -it apt-repo-24.04 bash Check Processes: ps aux | grep apt-mirror (shows if it's running, PID, and CPU/memory usage). top or htop (if installed) for resource monitoring. Kill if Needed: If stuck, kill then restart the loop: sh -c "while true; do apt-mirror; sleep 86400; done" & Exit: exit to leave the container.
-
Inspect Log Files (If Enabled)
Location: /var/spool/apt-mirror/var/log/apt-mirror.log (inside the container or on the host via the volume mount). Check on Host: tail -f /home/r3tr0/Documents/MyCreations/aptoffline/apt-mirror-24.04/var/log/apt-mirror.log (adjust path for 22.04). What It Shows: Detailed logs like download stats, errors, and timestamps. If the file doesn't exist, add set logfile $var_path/log/apt-mirror.log to mirror.list and rebuild. Alternative: docker exec apt-repo-24.04 tail -f /var/spool/apt-mirror/var/log/apt-mirror.log
-
Monitor Disk Usage and File Growth
On Host: du -sh /home/r3tr0/Documents/MyCreations/aptoffline/apt-mirror-24.04 (shows total size; run periodically to see growth). Inside Container: docker exec apt-repo-24.04 du -sh /var/spool/apt-mirror/mirror (for mirror size). Progress Indicator: Mirroring is complete when size stabilizes and logs show "Mirroring complete" or no new downloads.
-
Test the Repository
Access via Browser: Visit http://localhost:8081/archive.ubuntu.com/ubuntu/dists/noble/Release (adjust port/path). If it loads, mirroring is working. Apt Test: On a client, run sudo apt update pointing to the repo (as in previous steps). Success means it's ready.
Troubleshooting Tips
If No Progress: Ensure internet access, check for lock files (rm /var/spool/apt-mirror/var/lock), or run manually: docker exec apt-repo-24.04 apt-mirror.
Slow/Errors: Reduce nthreads in mirror.list or add proxy settings.
Completion Time: Initial mirror can take hours/days; subsequent updates are faster.
Use docker logs for quick checks. If you share log output, I can help diagnose issues!