Container Apps
Packaging Apps To Run on Any Linux Device
Innards
The Snapcraft docs explain some of the intricacies of which files do what inside a typical snap (not at the pre-build stage). Figure 2 shows the key files involved (source: The snap Format). It’s important not to confuse the snap.yaml and snapcraft.yaml files. The latter is used before the snap is compiled (i.e., the pre-build stage I mentioned before). The main file I’ll look at is the snapcraft.yaml file. To whet your appetite, Listing 1 is a snippet from such a file, with some pertinent comments.
In this basic example, you can see that this snippet is just “echoing” a string. Note that I'm intentionally using the relative path and not the usual absolute path, /usr/bin/host .
Listing 1: A Sample snapcraft.yaml File
--- name: Echo a name version: "1.0" # I'm a string not a number, so put me in quotes apps: echo-chrisbinnie: command: bin/echo # Note I drop the prepended slash to make it work inside a snap
Getting Your Hands Dirty
Now that I've touched on the basics, I’ll create a snap that does something useful. All the major distributions support snapd , from Arch Linux, Fedora, Gentoo, and openSUSE to OpenWrt and OpenEmbedded/Yocto, not to mention the obvious Debian and Ubuntu distributions.
I'll focus on my Linux Mint Debian laptop for convenience. To add the snapd package, I use the oh-so-arduous command (which might not even be necessary on some of the newer Ubuntu versions; I’ve read it’s built in from 16.04 onward):
$ sudo apt install snapd
Snaps are usually pulled from the Snap Store, which is comparable to the Docker Hub. To get going, it's a case of searching for your snap. Again, this process isn’t too dissimilar to using the Docker Hub. You’ll find a lot of pre-built snaps to work with.
Shopping
If you don’t have an Ubuntu One account, simply sign up. You’ll also be shownthe way to add your own snaps to the Snap Store once you’ve logged in. The marketing blurb includes the promise of getting your snap published within minutes and being able to reach millions of devices through the Snap Store.
Next, you will want to log in to the Snap Store:
$ snap login chris@binnie.tld
You should see a Login successful message.