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