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.

Snaps using bases

When using a base snap other than core, a custom Docker image will need to be used. For this, the Snapcraft maintainers publish a set of official OCI-compliant images.

Running a build

After either building or downloading the snapcraft Docker image, return to the root directory of the project containing your snapcraft.yaml and run snapcraft:

$ docker run -v "$PWD":/build -w /build <IMAGE-NAME> snapcraft

Repleace <IMAGE-NAME> with either the name of your manually built Docker image, mycustomimage:stable in our example above, or the downloaded image, such as canonical/snapcraft:8_core24.

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 month ago.