Creating docker images for snapcraft

Snapcraft is delivered as a snap and this creates a few complications when used with Docker. In particular, incompatible design constraints imposed by Docker affect the way snaps are intended to run. Fortunately, there are workarounds that can be used to create Docker images that will build snaps using Snapcraft.

What follows is a Dockerfile that can creates a docker image for Snapcraft from the stable channel: https://raw.githubusercontent.com/snapcore/snapcraft/master/docker/Dockerfile

The above Dockerfile can be used to build snaps with a snapcraft.yaml that either 1) defines base: core, or 2) doesn’t define a base at all. In both cases, the build environment is expected to be Ubuntu 16.04 LTS (Xenial Xerus).

To create a Dockerfile that can be used with base: core18 in snapcraft.yaml (the current default), change the line FROM ubuntu:xenial to FROM ubuntu:bionic in Dockerfile:

For more information on bases, see Base snaps.

:bulb: Reduce a snap’s build time by extending your project-specific Docker image to pre-install most of a snap’s dependencies, as defined by its snapcraft.yaml.

3 Likes

After https://github.com/snapcore/snapcraft/pull/2673 is merger, it will be possible to set both risk and Ubuntu flavor from the command line when building containers.

export RISK=stable
docker build --no-cache --tag snapcore/snapcraft:$RISK --build-arg RISK=$RISK --build-arg UBUNTU=bionic .
1 Like

The docs needs to be updated. I’ve sent the PR to remove the Dockerfile files docker: there is now the official repo with images by abitrolly · Pull Request #5063 · canonical/snapcraft · GitHub because there is now the official repo with images.