Building the snap on Docker


#1

Now that you have a snapcraft.yaml describing how to assemble your app and dependencies, you can build a snap.

You may already be using Docker for your build and test infrastructure. You can also use it to build snaps in these environments.

First, make sure you have Docker installed. You can test that Docker is correctly set up with:

docker run hello-world

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

Next, pull down the latest snapcraft image:

docker pull snapcore/snapcraft:stable

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 last command-line argument) from this same location inside the container.

If 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

Continue on to learn how to install, test, and publish your snap file.


Build on Docker
Building the snap
Proposed new documentation outline
Snap documentation
#2

I think this should be updated to mention that before running snapcraft from the container, apt update needs to be run, because as it is the snapcore/snapcraft docker image has out of date apt sources and as such snapcraft will fail to install/download packages when using apt because the sources/sites are out of date. So basically the command we should document for folks to run when using this docker image is:

docker run -v "$PWD":/build -w /build snapcore/snapcraft bash -c "apt update && snapcraft"

Build on Docker
#3

Thanks for this. I’ve merged the details from this topic into Build on Docker, which is currently linked from the documentation menu.