Installing snaps into docker images for k8s deployment

Hi.

I’ve got software distributed as snaps that I’d like to run under Kubernetes, in particular docker images deployed using Juju. However, during image build the ‘snap install’ fails because it is unable to talk to snapd (even after installing the snapd package). Which is obvious in hindsight because there is no systemd running to start it.

Has anyone got an example dockerfile that successfully installs a snap? And if you got that far, I’m guessing the next question is how to get k8s to run it?

Not to dismiss the request here for an example Dockerfile, but just so you’re aware of the technical limitations that prevent us from making snaps work well inside docker containers, see my response here.

Perhaps you could use lxd containers instead of docker containers? I’m not sure how one hooks up lxd to k8s/juju however so perhaps that’s not an option.

It doesn’t seem possible to have Kubernetes spin up lxd containers unfortunately (that would be ideal for my work).

I’m actually not bothered if snaps do not run well. I’m mostly interested in getting them running at all. In this environment, I would not be concerned if security policies are unenforced, because in this environment containment is not our concern. Automatic upgrades would make use of snapped software more compelling in docker images (software updates seem to be left as an exercise to the user, which is a problem for production environments and raises compliance issues), but wouldn’t be critical since that is a problem we already have with apt packaging (no systemd, no cron, no unattended-upgrades, no log rotation).

I think my biggest problem is lack of systemd, ie. that I’m stuck with application containers rather than OS containers. Even if I could solve the snap issue, I’ve got a couple of other more to wrangle, but that is off topic to this forum :slight_smile:

You can take a look at the repository below for inspiration. It is for getting snapcraft running, but can be customised to suit other snaps:

Aside: If you’re interested in using docker containers to build snap packages then I wrote up a blog post about the above code at:

https://snapcraft.ninja/2020/08/03/snapcraft-continuous-integration-github-actions/