github.com/portworx/docker@v1.12.1/docs/examples/apt-cacher-ng.md (about)

     1  <!--[metadata]>
     2  +++
     3  title = "Dockerizing an apt-cacher-ng service"
     4  description = "Installing and running an apt-cacher-ng service"
     5  keywords = ["docker, example, package installation, networking, debian,  ubuntu"]
     6  [menu.main]
     7  parent = "engine_dockerize"
     8  +++
     9  <![end-metadata]-->
    10  
    11  # Dockerizing an apt-cacher-ng service
    12  
    13  > **Note**:
    14  > - **If you don't like sudo** then see [*Giving non-root
    15  >   access*](../installation/binaries.md#giving-non-root-access).
    16  > - **If you're using OS X or docker via TCP** then you shouldn't use
    17  >   sudo.
    18  
    19  When you have multiple Docker servers, or build unrelated Docker
    20  containers which can't make use of the Docker build cache, it can be
    21  useful to have a caching proxy for your packages. This container makes
    22  the second download of any package almost instant.
    23  
    24  Use the following Dockerfile:
    25  
    26      #
    27      # Build: docker build -t apt-cacher .
    28      # Run: docker run -d -p 3142:3142 --name apt-cacher-run apt-cacher
    29      #
    30      # and then you can run containers with:
    31      #   docker run -t -i --rm -e http_proxy http://dockerhost:3142/ debian bash
    32      #
    33      # Here, `dockerhost` is the IP address or FQDN of a host running the Docker daemon
    34      # which acts as an APT proxy server.
    35      FROM        ubuntu
    36      MAINTAINER  SvenDowideit@docker.com
    37  
    38      VOLUME      ["/var/cache/apt-cacher-ng"]
    39      RUN     apt-get update && apt-get install -y apt-cacher-ng
    40  
    41      EXPOSE      3142
    42      CMD     chmod 777 /var/cache/apt-cacher-ng && /etc/init.d/apt-cacher-ng start && tail -f /var/log/apt-cacher-ng/*
    43  
    44  To build the image using:
    45  
    46      $ docker build -t eg_apt_cacher_ng .
    47  
    48  Then run it, mapping the exposed port to one on the host
    49  
    50      $ docker run -d -p 3142:3142 --name test_apt_cacher_ng eg_apt_cacher_ng
    51  
    52  To see the logfiles that are `tailed` in the default command, you can
    53  use:
    54  
    55      $ docker logs -f test_apt_cacher_ng
    56  
    57  To get your Debian-based containers to use the proxy, you have
    58  following options.  Note that you must replace `dockerhost` with the
    59  IP address or FQDN of the host running the `test_apt_cacher_ng`
    60  container.
    61  
    62  1. Add an apt Proxy setting
    63     `echo 'Acquire::http { Proxy "http://dockerhost:3142"; };' >> /etc/apt/conf.d/01proxy`
    64  2. Set an environment variable:
    65     `http_proxy=http://dockerhost:3142/`
    66  3. Change your `sources.list` entries to start with
    67     `http://dockerhost:3142/`
    68  4. Link Debian-based containers to the APT proxy container using `--link`
    69  5. Create a custom network of an APT proxy container with Debian-based containers.
    70  
    71  **Option 1** injects the settings safely into your apt configuration in
    72  a local version of a common base:
    73  
    74      FROM ubuntu
    75      RUN  echo 'Acquire::http { Proxy "http://dockerhost:3142"; };' >> /etc/apt/apt.conf.d/01proxy
    76      RUN apt-get update && apt-get install -y vim git
    77  
    78      # docker build -t my_ubuntu .
    79  
    80  **Option 2** is good for testing, but will break other HTTP clients
    81  which obey `http_proxy`, such as `curl`, `wget` and others:
    82  
    83      $ docker run --rm -t -i -e http_proxy=http://dockerhost:3142/ debian bash
    84  
    85  **Option 3** is the least portable, but there will be times when you
    86  might need to do it and you can do it from your `Dockerfile`
    87  too.
    88  
    89  **Option 4** links Debian-containers to the proxy server using following command:
    90  
    91      $ docker run -i -t --link test_apt_cacher_ng:apt_proxy -e http_proxy=http://apt_proxy:3142/ debian bash
    92  
    93  **Option 5** creates a custom network of APT proxy server and Debian-based containers:
    94  
    95      $ docker network create mynetwork
    96      $ docker run -d -p 3142:3142 --network=mynetwork --name test_apt_cacher_ng eg_apt_cacher_ng
    97      $ docker run --rm -it --network=mynetwork -e http_proxy=http://test_apt_cacher_ng:3142/ debian bash
    98  
    99  Apt-cacher-ng has some tools that allow you to manage the repository,
   100  and they can be used by leveraging the `VOLUME`
   101  instruction, and the image we built to run the service:
   102  
   103      $ docker run --rm -t -i --volumes-from test_apt_cacher_ng eg_apt_cacher_ng bash
   104  
   105      $$ /usr/lib/apt-cacher-ng/distkill.pl
   106      Scanning /var/cache/apt-cacher-ng, please wait...
   107      Found distributions:
   108      bla, taggedcount: 0
   109           1. precise-security (36 index files)
   110           2. wheezy (25 index files)
   111           3. precise-updates (36 index files)
   112           4. precise (36 index files)
   113           5. wheezy-updates (18 index files)
   114  
   115      Found architectures:
   116           6. amd64 (36 index files)
   117           7. i386 (24 index files)
   118  
   119      WARNING: The removal action may wipe out whole directories containing
   120               index files. Select d to see detailed list.
   121  
   122      (Number nn: tag distribution or architecture nn; 0: exit; d: show details; r: remove tagged; q: quit): q
   123  
   124  Finally, clean up after your test by stopping and removing the
   125  container, and then removing the image.
   126  
   127      $ docker stop test_apt_cacher_ng
   128      $ docker rm test_apt_cacher_ng
   129      $ docker rmi eg_apt_cacher_ng