Tag Archives: docker

Dockerfile: “no such file or directory” error using ADD

Testing docker is really interesting, but sometimes it’s difficult to understand what’s wrong with some configuration.

A problem I found recently dealed with the ADD directive used in the Dockerfile. I was trying to start some services with supervisor but I got this error during the image build process

Step 19 : ADD supervisord.conf /etc/supervisor/conf.d/
2014/02/10 00:40:55 build: supervisord.conf: no such file or directory

The file was right there, in the same path of the Dockerfile, but docker couldn’t find it.

After a good read of the official documentation I learned the conxept of “build context”. When you are building an image, the source directory from which you are operating is the build context, but when you are building passing the Dockerfile from the standard input, there’s no build context!

So this is ok

$ docker build -t mydebian .

and this can’t work

$ docker build -t mydebian - < Dockerfile

Cache deb packages with apt-cacher-ng

I’m playing with Docker and I’m constantly tuning my Dockerfile to install the needed packages.

This continuous refinement forces the build process to download the same deb packages every time and it becomes an actual waste of time and bandwidth.

Solution

apt-cacher-ng is a service which can be run on a Debian or Ubuntu host and will serve as a local cache for deb packages from Debian or Ubuntu repositories.

That’s what I need because I’m on an Ubuntu machine emulating a Debian container.

Host setup

The setup is really easy:

# aptitude install apt-cacher-ng

After the installation I changed the bind address of the service to keep it local (I don’t need LAN exposure), I added my local proxy to reach the internet and I disabled ReuseConnections (see Problems):

root@yoda:/etc/apt-cacher-ng# diff acng.conf acng.conf.old 
28d27
< BindAddress: localhost 172.17.42.1
35d33
< proxy: http://127.0.0.1:5865
322d319
< ReuseConnections: 0

Client setup

On the client side it’s necessary to force apt requests to use the proxy.
In the Dockerfile I added

RUN echo 'Acquire::http::Proxy "http://172.17.42.1:3142";' > /etc/apt/apt.conf.d/90-apt-cacher.conf

which creates the configuration file read by apt-get or aptitude when downloading packages.

Problems

The apt-cacher-ng server seems buggy at least when used in conjunction with a regular proxy. Sometimes I get errors like these on the client side

Err http://http.debian.net/debian/ wheezy/main netbase all 5.0
500  Invalid header

one possible solution is to perform a

# apt-get update

on the host machine (it seems to help). Another useful setting is

ReuseConnections: 0

as explained before.