Build on Docker

Snapcraft, the snap-building tool, is designed to use Multipass and bases to both simplify the build process and to confine the build environment within a virtual machine. This mostly removes the need to use Docker.

However, Docker can still be used, and is particularly useful when you’re already using Docker within your build and test infrastructure.
All you need is a working snapcraft.yaml (see Creating a snap for more details).

To create a snap with Docker, first make sure you have Docker installed. You can test that Docker is correctly set up with:

$ docker run hello-world
Status: Downloaded newer image for hello-world:latest

Hello from Docker!

If you don’t see the “Hello from Docker!” message, consult the Docker documentation for troubleshooting steps.

Next, if your snapcraft.yaml has no base entry or base: core defined, pull down the latest snapcraft image:

$ docker pull snapcore/snapcraft:stable
Status: Downloaded newer image for snapcore/snapcraft:stable

If you are using any other base, refer to Creating Docker images for snapcraft to use as a reference to create your own docker image.

Return to the root directory of the project containing your snapcraft.yaml and run snapcraft:

$ docker run -v "$PWD":/build -w /build snapcore/snapcraft:stable snapcraft

These options instruct Docker to map the current directory, your project root, to the /snapcraft_build directory inside the container, and then start the snapcraft command (the final command-line argument) from this same location inside the container.

When the snap build completes successfully, you will find a .snap file in the current directory. You can inspect its contents to ensure it contains all of your application’s assets:

$ unsquashfs -l *.snap

Next steps

After creating a snap, you should upload it to the Snap Store, from where it can reach a potential audience of millions. See Releasing your app for further details.

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