I've run into an issue with an outage at my usual apt package repository, making it impossible to download packages needed for my Docker image builds. I have a Nexus server set up to cache various packages, including Python and Docker images, and I noticed it can also act as an apt proxy repository. Is there a way to configure 'docker build' to utilize my local apt proxy instead of the default repository during the build process and cache the apt packages? I'm thinking about using something like a build argument to pass the proxy URL. Any suggestions?
1 Answer
Absolutely! I’ve set this up with Nexus myself, and it works like a charm. You can definitely configure apt to point to your local proxy during builds. Just modify the sources.list or use build arguments to define your proxy URL.
What I did was create a base image with the sources.list directed at my Nexus, and the other images inherit from it. Alternatively, you can utilize a build argument like `--build-arg APT_PROXY=http://your-nexus:8081/repository/apt-proxy/` and then include a command in your Dockerfile such as `RUN echo "deb $APT_PROXY focal main" > /etc/apt/sources.list`.
Once the cache is warmed up, it speeds up your rebuilds, but just keep Nexus running locally to avoid build failures! I had to tweak the Nexus apt proxy settings initially, but after that, it's smooth sailing!

Great, I’ll give that a go! I regularly recreate Docker images in my CI/CD process with Jenkins, so having the local cache will be a big help. Just one thing: will this embed the Nexus URL directly into the image layer?