2015-06-07 23:07:20 -04:00
|
|
|
<!--[metadata]>
|
|
|
|
+++
|
|
|
|
title = "Dockerizing an apt-cacher-ng service"
|
|
|
|
description = "Installing and running an apt-cacher-ng service"
|
|
|
|
keywords = ["docker, example, package installation, networking, debian, ubuntu"]
|
|
|
|
[menu.main]
|
2016-01-23 23:36:40 -05:00
|
|
|
parent = "engine_dockerize"
|
2015-06-07 23:07:20 -04:00
|
|
|
+++
|
|
|
|
<![end-metadata]-->
|
2014-04-15 20:53:12 -04:00
|
|
|
|
2015-04-21 11:50:09 -04:00
|
|
|
# Dockerizing an apt-cacher-ng service
|
2014-04-15 20:53:12 -04:00
|
|
|
|
2016-01-23 23:36:40 -05:00
|
|
|
> **Note**:
|
2015-10-09 19:50:41 -04:00
|
|
|
> - **If you don't like sudo** then see [*Giving non-root
|
|
|
|
> access*](../installation/binaries.md#giving-non-root-access).
|
|
|
|
> - **If you're using OS X or docker via TCP** then you shouldn't use
|
|
|
|
> sudo.
|
2014-04-15 20:53:12 -04:00
|
|
|
|
|
|
|
When you have multiple Docker servers, or build unrelated Docker
|
2014-04-23 16:48:28 -04:00
|
|
|
containers which can't make use of the Docker build cache, it can be
|
2014-04-15 20:53:12 -04:00
|
|
|
useful to have a caching proxy for your packages. This container makes
|
|
|
|
the second download of any package almost instant.
|
|
|
|
|
|
|
|
Use the following Dockerfile:
|
|
|
|
|
|
|
|
#
|
|
|
|
# Build: docker build -t apt-cacher .
|
|
|
|
# Run: docker run -d -p 3142:3142 --name apt-cacher-run apt-cacher
|
|
|
|
#
|
|
|
|
# and then you can run containers with:
|
|
|
|
# docker run -t -i --rm -e http_proxy http://dockerhost:3142/ debian bash
|
|
|
|
#
|
2016-01-04 02:00:10 -05:00
|
|
|
# Here, `dockerhost` is the IP address or FQDN of a host running the Docker daemon
|
|
|
|
# which acts as an APT proxy server.
|
2014-04-15 20:53:12 -04:00
|
|
|
FROM ubuntu
|
|
|
|
MAINTAINER SvenDowideit@docker.com
|
|
|
|
|
|
|
|
VOLUME ["/var/cache/apt-cacher-ng"]
|
2014-07-07 14:06:34 -04:00
|
|
|
RUN apt-get update && apt-get install -y apt-cacher-ng
|
2014-04-15 20:53:12 -04:00
|
|
|
|
|
|
|
EXPOSE 3142
|
2014-07-07 14:06:34 -04:00
|
|
|
CMD chmod 777 /var/cache/apt-cacher-ng && /etc/init.d/apt-cacher-ng start && tail -f /var/log/apt-cacher-ng/*
|
2014-04-15 20:53:12 -04:00
|
|
|
|
|
|
|
To build the image using:
|
|
|
|
|
2015-03-26 14:12:37 -04:00
|
|
|
$ docker build -t eg_apt_cacher_ng .
|
2014-04-15 20:53:12 -04:00
|
|
|
|
|
|
|
Then run it, mapping the exposed port to one on the host
|
|
|
|
|
2015-03-26 14:12:37 -04:00
|
|
|
$ docker run -d -p 3142:3142 --name test_apt_cacher_ng eg_apt_cacher_ng
|
2014-04-15 20:53:12 -04:00
|
|
|
|
2014-04-23 16:48:28 -04:00
|
|
|
To see the logfiles that are `tailed` in the default command, you can
|
2014-04-15 20:53:12 -04:00
|
|
|
use:
|
|
|
|
|
2015-03-26 14:12:37 -04:00
|
|
|
$ docker logs -f test_apt_cacher_ng
|
2014-04-15 20:53:12 -04:00
|
|
|
|
2016-06-19 15:28:08 -04:00
|
|
|
To get your Debian-based containers to use the proxy, you have
|
|
|
|
following options. Note that you must replace `dockerhost` with the
|
|
|
|
IP address or FQDN of the host running the `test_apt_cacher_ng`
|
|
|
|
container.
|
2014-04-15 20:53:12 -04:00
|
|
|
|
2014-04-23 16:48:28 -04:00
|
|
|
1. Add an apt Proxy setting
|
|
|
|
`echo 'Acquire::http { Proxy "http://dockerhost:3142"; };' >> /etc/apt/conf.d/01proxy`
|
|
|
|
2. Set an environment variable:
|
|
|
|
`http_proxy=http://dockerhost:3142/`
|
|
|
|
3. Change your `sources.list` entries to start with
|
|
|
|
`http://dockerhost:3142/`
|
2016-01-04 02:00:10 -05:00
|
|
|
4. Link Debian-based containers to the APT proxy container using `--link`
|
|
|
|
5. Create a custom network of an APT proxy container with Debian-based containers.
|
2014-04-15 20:53:12 -04:00
|
|
|
|
|
|
|
**Option 1** injects the settings safely into your apt configuration in
|
|
|
|
a local version of a common base:
|
|
|
|
|
|
|
|
FROM ubuntu
|
|
|
|
RUN echo 'Acquire::http { Proxy "http://dockerhost:3142"; };' >> /etc/apt/apt.conf.d/01proxy
|
2014-07-07 14:06:34 -04:00
|
|
|
RUN apt-get update && apt-get install -y vim git
|
2014-04-15 20:53:12 -04:00
|
|
|
|
|
|
|
# docker build -t my_ubuntu .
|
|
|
|
|
|
|
|
**Option 2** is good for testing, but will break other HTTP clients
|
2014-04-17 18:55:24 -04:00
|
|
|
which obey `http_proxy`, such as `curl`, `wget` and others:
|
2014-04-15 20:53:12 -04:00
|
|
|
|
2015-03-26 14:12:37 -04:00
|
|
|
$ docker run --rm -t -i -e http_proxy=http://dockerhost:3142/ debian bash
|
2014-04-15 20:53:12 -04:00
|
|
|
|
|
|
|
**Option 3** is the least portable, but there will be times when you
|
|
|
|
might need to do it and you can do it from your `Dockerfile`
|
|
|
|
too.
|
|
|
|
|
2016-01-04 02:00:10 -05:00
|
|
|
**Option 4** links Debian-containers to the proxy server using following command:
|
|
|
|
|
|
|
|
$ docker run -i -t --link test_apt_cacher_ng:apt_proxy -e http_proxy=http://apt_proxy:3142/ debian bash
|
|
|
|
|
|
|
|
**Option 5** creates a custom network of APT proxy server and Debian-based containers:
|
|
|
|
|
|
|
|
$ docker network create mynetwork
|
2016-06-06 19:33:00 -04:00
|
|
|
$ docker run -d -p 3142:3142 --network=mynetwork --name test_apt_cacher_ng eg_apt_cacher_ng
|
|
|
|
$ docker run --rm -it --network=mynetwork -e http_proxy=http://test_apt_cacher_ng:3142/ debian bash
|
2016-01-04 02:00:10 -05:00
|
|
|
|
2014-04-15 20:53:12 -04:00
|
|
|
Apt-cacher-ng has some tools that allow you to manage the repository,
|
|
|
|
and they can be used by leveraging the `VOLUME`
|
|
|
|
instruction, and the image we built to run the service:
|
|
|
|
|
2015-03-26 14:12:37 -04:00
|
|
|
$ docker run --rm -t -i --volumes-from test_apt_cacher_ng eg_apt_cacher_ng bash
|
2014-04-15 20:53:12 -04:00
|
|
|
|
|
|
|
$$ /usr/lib/apt-cacher-ng/distkill.pl
|
|
|
|
Scanning /var/cache/apt-cacher-ng, please wait...
|
|
|
|
Found distributions:
|
|
|
|
bla, taggedcount: 0
|
|
|
|
1. precise-security (36 index files)
|
|
|
|
2. wheezy (25 index files)
|
|
|
|
3. precise-updates (36 index files)
|
|
|
|
4. precise (36 index files)
|
|
|
|
5. wheezy-updates (18 index files)
|
|
|
|
|
|
|
|
Found architectures:
|
|
|
|
6. amd64 (36 index files)
|
|
|
|
7. i386 (24 index files)
|
|
|
|
|
|
|
|
WARNING: The removal action may wipe out whole directories containing
|
|
|
|
index files. Select d to see detailed list.
|
|
|
|
|
|
|
|
(Number nn: tag distribution or architecture nn; 0: exit; d: show details; r: remove tagged; q: quit): q
|
|
|
|
|
|
|
|
Finally, clean up after your test by stopping and removing the
|
|
|
|
container, and then removing the image.
|
|
|
|
|
2015-03-26 14:12:37 -04:00
|
|
|
$ docker stop test_apt_cacher_ng
|
|
|
|
$ docker rm test_apt_cacher_ng
|
|
|
|
$ docker rmi eg_apt_cacher_ng
|