apt-cacher-ng.rst 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. :title: Running an apt-cacher-ng service
  2. :description: Installing and running an apt-cacher-ng service
  3. :keywords: docker, example, package installation, networking, debian, ubuntu
  4. .. _running_apt-cacher-ng_service:
  5. Apt-Cacher-ng Service
  6. =====================
  7. .. include:: example_header.inc
  8. When you have multiple Docker servers, or build unrelated Docker containers
  9. which can't make use of the Docker build cache, it can be useful to have a
  10. caching proxy for your packages. This container makes the second download of
  11. any package almost instant.
  12. Use the following Dockerfile:
  13. .. literalinclude:: apt-cacher-ng.Dockerfile
  14. To build the image using:
  15. .. code-block:: bash
  16. $ sudo docker build -rm -t eg_apt_cacher_ng .
  17. Then run it, mapping the exposed port to one on the host
  18. .. code-block:: bash
  19. $ sudo docker run -d -p 3142:3142 -name test_apt_cacher_ng eg_apt_cacher_ng
  20. To see the logfiles that are 'tailed' in the default command, you can use:
  21. .. code-block:: bash
  22. $ sudo docker logs -f test_apt_cacher_ng
  23. To get your Debian based containers to use the proxy, you can do one of 3 things
  24. 1. Set and environment variable: ``http_proxy=http://dockerhost:3142/``
  25. 2. Add an apt Proxy setting ``echo 'Acquire::http { Proxy "http://dockerhost:3142"; };' >> /etc/apt/conf.d/01proxy``
  26. 3. Change your sources.list entries to start with ``http://dockerhost:3142/``
  27. Option 1 will work for running a container, so is good for testing, but will
  28. break any non-apt http requests, like ``curl``, ``wget`` and more.:
  29. .. code-block:: bash
  30. $ sudo docker run -rm -t -i -e http_proxy=http://dockerhost:3142/ debian bash
  31. Or you can inject the settings safely into your apt configuration in a local
  32. version of a common base:
  33. .. code-block:: bash
  34. FROM ubuntu
  35. RUN echo 'Acquire::http { Proxy "http://dockerhost:3142"; };' >> /etc/apt/apt.conf.d/01proxy
  36. RUN apt-get update ; apt-get install vim git
  37. # docker build -t my_ubuntu .
  38. Option 3 is the least portable, but there will be times when you might need to
  39. do it - and you can do it from your Dockerfile too.
  40. Apt-cacher-ng has some tools that allow you to manage the repository, and they
  41. can be used by leveraging the ``VOLUME``, and the image we built to run the
  42. service:
  43. .. code-block:: bash
  44. $ sudo docker run -rm -t -i --volumes-from test_apt_cacher_ng eg_apt_cacher_ng bash
  45. $$ /usr/lib/apt-cacher-ng/distkill.pl
  46. Scanning /var/cache/apt-cacher-ng, please wait...
  47. Found distributions:
  48. bla, taggedcount: 0
  49. 1. precise-security (36 index files)
  50. 2. wheezy (25 index files)
  51. 3. precise-updates (36 index files)
  52. 4. precise (36 index files)
  53. 5. wheezy-updates (18 index files)
  54. Found architectures:
  55. 6. amd64 (36 index files)
  56. 7. i386 (24 index files)
  57. WARNING: The removal action may wipe out whole directories containing
  58. index files. Select d to see detailed list.
  59. (Number nn: tag distribution or architecture nn; 0: exit; d: show details; r: remove tagged; q: quit): q
  60. Finally, clean up after your test by stopping and removing the container, and
  61. then removing the image.
  62. .. code-block:: bash
  63. $ sudo docker stop test_apt_cacher_ng
  64. $ sudo docker rm test_apt_cacher_ng
  65. $ sudo docker rmi eg_apt_cacher_ng