Configure cloud-init for apt primary uri

I’m having problems using a different sources.list in my ubuntu container than the original.

I have added an /etc/apt/sources.list.d/sources.list inside the container after boot, but when I run apt-get update the original /etc/apt/sources.list take precedence.

This is ultimately what I’m trying to solve and I thought I’d do that by configuring the apt primary uri as mentioned in cloud-init. Nothing I do seems to work though.

lxc launch ubuntu:16.04 $CONTAINER_NAME -c security.privileged=true
lxc config set $CONTAINER_NAME user.user-data - < config.yml



Shouldn’t my /etc/apt/sources.list contain the apt primary uri?

I don’t know that much about cloud-init, but here I’m instead using:


Note that cloud-init only runs on the first boot of the container, so with the commands above, you’re likely setting it too late. You could use lxc init instead of lxc launch, then run lxc start.

Or you could put the cloud-init bits in your default profile, so that they apply to all containers spawned on your system. If you do so, you may want to use the user.vendor-data key instead of user.user-data as that will then let you still use user.user-data for any container-local configuration.

That worked a treat. Thanks very much.

The apt_mirror config key doesn’t really match any cloud-init documentation I could find anyway.
Mind me asking where this comes from and how you know?

This appears very much like black magic :slight_smile:


It might be an older key, I know that some of them got renamed at some point, but that’s what I’ve had in my user.vendor-data for a few years now :slight_smile: