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