Skip to content

Dockerfile to create a Docker container image for Apt-Cacher NG

License

Notifications You must be signed in to change notification settings

aporquez/docker-apt-cacher-ng

 
 

Repository files navigation

aporquez/apt-cacher-ng:latest


Introduction

This git repository helps you installing and running Apt-Cacher NG quickly on your local machine.

Apt-Cacher NG is a caching proxy, specialized for package files from Linux distributors, primarily for Debian (and Debian based) distributions but not limited to those.

This repository is to create a Docker container image for Apt-Cacher NG.It is a modified version of sameersbn/docker-apt-cacher-ng, lurcio/docker-apt-cacher-ng and seifer08ms/docker-apt-cacher-ng with a few changes including docker compose version, updated the docker FROM image, and updated the setup.sh to cache the packages/indexes from SSL/TLS(HTTPS). Many thanks guys!

Switching offline mode

This feature is the major update from original codes. The Docker container can automatically check network and choose offline or online mode in the beginning of startup. If the network condition is change during running, you can restart it to check it again using docker restart apt-cacher-ng.

Getting started

Installation

Automated builds of the image are available on Dockerhub and is the recommended method of installation.

docker pull akeno379/apt-cacher-ng:latest

Alternatively you can build the image yourself with make command.

make

Quickstart

Start Apt-Cacher NG daemon using:

make install HOST_CACHE_DIR=/srv/docker/apt-cacher-ng

This commnad could mounts a volume for persistence. The parameter HOST_CACHE_DIR denotes the location of mounting a volume at /var/cache/apt-cacher-ng.

Alternatively, you can use the sample docker-compose.yml file to start the container using Docker Compose

Usage

To start using Apt-Cacher NG on your Debian (and Debian based) host, create the configuration file /etc/apt/apt.conf.d/01proxy with the following content:

Acquire::HTTP::Proxy "http://172.17.42.1:3142";
Acquire::HTTPS::Proxy "false";

Similarly, to use Apt-Cacher NG in you Docker containers add the following line to your Dockerfile before any apt-get commands.

RUN echo 'Acquire::HTTP::Proxy "http://172.17.42.1:3142";' >> /etc/apt/apt.conf.d/01proxy \
 && echo 'Acquire::HTTPS::Proxy "false";' >> /etc/apt/apt.conf.d/01proxy

By default apt-cacher-ng doesn't cache the packages/indexes from SSL/TLS(HTTPS). To make apt-cacher-ng cache the packages/indexes via SSL/TLS repositories, we will have to configure apt-cacher-ng to remap a chosen non-https repository url to the actual https url.

Create a file named backends_packages in /etc/apt-cacher-ng that looks like:

https://download.docker.com/linux/ubuntu

Now, in apt-cacher-ng /etc/apt-cacher-ng/acng.conf we can specify a mapping like:

#Remap-RepositoryName: MergingURLs ; TargetURLs ; OptionalFlags

Remap-docker: http://fakedomain.com ; file:backends_packages

We can now configure all our clients to use http://fakedomain.com instead of https://download.docker.com/linux/ubuntu, and apt-cacher-ng will transparently proxy, and more importantly, cache, objects from https://download.docker.com/linux/ubuntu. For more example check the setup.sh.

Note: You may need to add the GPG Key to the machine that uses the proxy.

Upgrading

To upgrade to newer releases:

  1. Download the updated Docker image:
make pull
  1. Stop and remove the container:
make clean
  1. Start the updated image
make install

Shell Access

For debugging and maintenance purposes you may want access the containers shell:

make shell

Further help

See also lurcio/docker-apt-cacher-ng

About

Dockerfile to create a Docker container image for Apt-Cacher NG

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Shell 61.8%
  • Dockerfile 21.5%
  • Makefile 16.7%