github.com/akashshinde/docker@v1.9.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 = "smn_applied"
     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      FROM        ubuntu
    34      MAINTAINER  SvenDowideit@docker.com
    35  
    36      VOLUME      ["/var/cache/apt-cacher-ng"]
    37      RUN     apt-get update && apt-get install -y apt-cacher-ng
    38  
    39      EXPOSE      3142
    40      CMD     chmod 777 /var/cache/apt-cacher-ng && /etc/init.d/apt-cacher-ng start && tail -f /var/log/apt-cacher-ng/*
    41  
    42  To build the image using:
    43  
    44      $ docker build -t eg_apt_cacher_ng .
    45  
    46  Then run it, mapping the exposed port to one on the host
    47  
    48      $ docker run -d -p 3142:3142 --name test_apt_cacher_ng eg_apt_cacher_ng
    49  
    50  To see the logfiles that are `tailed` in the default command, you can
    51  use:
    52  
    53      $ docker logs -f test_apt_cacher_ng
    54  
    55  To get your Debian-based containers to use the proxy, you can do one of
    56  three things
    57  
    58  1. Add an apt Proxy setting
    59     `echo 'Acquire::http { Proxy "http://dockerhost:3142"; };' >> /etc/apt/conf.d/01proxy`
    60  2. Set an environment variable:
    61     `http_proxy=http://dockerhost:3142/`
    62  3. Change your `sources.list` entries to start with
    63     `http://dockerhost:3142/`
    64  
    65  **Option 1** injects the settings safely into your apt configuration in
    66  a local version of a common base:
    67  
    68      FROM ubuntu
    69      RUN  echo 'Acquire::http { Proxy "http://dockerhost:3142"; };' >> /etc/apt/apt.conf.d/01proxy
    70      RUN apt-get update && apt-get install -y vim git
    71  
    72      # docker build -t my_ubuntu .
    73  
    74  **Option 2** is good for testing, but will break other HTTP clients
    75  which obey `http_proxy`, such as `curl`, `wget` and others:
    76  
    77      $ docker run --rm -t -i -e http_proxy=http://dockerhost:3142/ debian bash
    78  
    79  **Option 3** is the least portable, but there will be times when you
    80  might need to do it and you can do it from your `Dockerfile`
    81  too.
    82  
    83  Apt-cacher-ng has some tools that allow you to manage the repository,
    84  and they can be used by leveraging the `VOLUME`
    85  instruction, and the image we built to run the service:
    86  
    87      $ docker run --rm -t -i --volumes-from test_apt_cacher_ng eg_apt_cacher_ng bash
    88  
    89      $$ /usr/lib/apt-cacher-ng/distkill.pl
    90      Scanning /var/cache/apt-cacher-ng, please wait...
    91      Found distributions:
    92      bla, taggedcount: 0
    93           1. precise-security (36 index files)
    94           2. wheezy (25 index files)
    95           3. precise-updates (36 index files)
    96           4. precise (36 index files)
    97           5. wheezy-updates (18 index files)
    98  
    99      Found architectures:
   100           6. amd64 (36 index files)
   101           7. i386 (24 index files)
   102  
   103      WARNING: The removal action may wipe out whole directories containing
   104               index files. Select d to see detailed list.
   105  
   106      (Number nn: tag distribution or architecture nn; 0: exit; d: show details; r: remove tagged; q: quit): q
   107  
   108  Finally, clean up after your test by stopping and removing the
   109  container, and then removing the image.
   110  
   111      $ docker stop test_apt_cacher_ng
   112      $ docker rm test_apt_cacher_ng
   113      $ docker rmi eg_apt_cacher_ng