Base snaps

A base snap is a special kind of snap that provides a run-time environment with a minimal set of libraries that are common to most applications. They’re transparent to users, but they need to be considered, and specified, when building a snap.

Bases are defined by adding the base: keyword to a snap’s snapcraft.yaml followed by the base name.

There are currently two supported bases:

core16 is currently under development. With no current stable release, its beta and candidate releases are classed as experimental. As with core18 (and distinct from core), it’s built without bundling snapd and its associated tools. In both core16 and core18, these are are instead provided by their associated snaps.

:information_source: Older releases of core were occasionally referred to as core 16, but core and core16 are now two distinct packages.

For example, to specify core 18, use the following:

base: core18

To specify core, use the following

base: core

The base snap mounts itself as the root filesystem within your snap such that when your application runs, the base’s library paths are searched directly after the paths for your specific snap.

When building your snap with no specified base, Snapcraft will operate in compatibility mode. This is essentially a prior (2.43-era) version of Snapcraft, and will lose the functionality of newer releases. See Features incompatible with bases for details.

Choosing a base

core18 is the recommended base for the majority of snaps. It’s synonymous with the latest Long Term Support release of Ubuntu, Ubuntu 18.04 LTS, and it’s what the snapcraft init command includes when generating a new project’s template snapcraft.yaml.

But much like choosing a distribution base for a project or server, the best base for an application is dependent on an application’s requirements. If there are specific dependencies that cannot be easily met with core18 then core is a valid and supported alternative.

Base support was added with the release of Snapcraft 3. As noted above, snaps created before this, and snaps not using the base: keyword, can still be built but they cannot use specific new features. Instead, snaps built without bases inherit attributes from their respective build environments.

Snaps that don’t use bases can often migrate to one without too much difficulty. See Upgrading snapcraft for more details on potential differences.

Building a base snap

While it is possible to build your own base snap, its publisher needs to take responsibility for its maintenance and updates. In particular:

  • bases need to be built from stable packages
  • ABI compatibility cannot broken (ie. never replace symbols or libraries, and be strict)
  • security updates must be pro-active

Base snaps can be either bootable or non-bootable. The former needs to include systemd while the latter can be leaner.

build-base

The base keyword on its own does not not take into account the creation of bases. Instead, with older versions of snapcraft, the name keyword was arbitrarily used to determine the build environment:

name: core18
type: base
# base: is not set elsewhere 

The above example uses name to specify the creation of an Ubuntu 18.04 (core18) based build environment.

But the above fails if a base has yet to be bootstrapped, or is otherwise unavailable. For example, the following will currently generate a `launch failed: Unable to find an image matching “core20” error:

name: core20
type: base
# base: is not set elsewhere 

In cases like the above, where the base has not yet been bootstrapped, the build-base keyword should be used to explicitly define the base to use for the build environment.

To solve the above issue, for example, use the following:

name: core20
type: base
build-base: core18
# base: is not set elsewhere 

Last updated a month ago. Help improve this document in the forum.