Ubuntu how to set apt.conf and proxy during image building

I’m trying build a vagrant/virtualbox image box but getting the error:
Unable to connect to archive.ubuntu.com:http:
How can I set proxy config in the VM before the building process starts?

Hello,

Are you receiving this error when Packer is attempting to download the source image? If so, you should be able to set the HTTP_PROXY environment variable prior to running packer build and it will use the specified proxy.

No. It occurs when apt update is executing.

Hi,

According to man 1 apt-transport-http, Apt should respect & use a proxy defined in the HTTP_PROXY environment variable.

Assuming you’re using a shell provisioner to install packages, you should be able to specify export HTTP_PROXY=<address> prior to the apt command which installs your packages, and apt should use that proxy.

If that doesn’t work, you can explicitly configure one in apt.conf. See the bottom of that man page for an example.