Build on Docker
Snapcraft 3.0, 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, it’s still possible to use Docker if your build environment requires it.
To get started, first check whether Docker is already installed. This can be done with the following command (look for Hello from Docker in the output):
$ docker run hello-world ... Hello from Docker! This message shows that your installation appears to be working correctly. ...
If Docker isn’t installed, take a look at Install Docker. Ubuntu users can alternatively step through the following:
Install Docker on Ubuntu 16.04 LTS (or later)
Update the package details held on your system:
$ sudo apt-get update
Download and add Docker’s third-party repository key:
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
Next, add Docker’s package repository:
$ sudo add-apt-repository -u \ "deb [arch=amd64] https://download.docker.com/linux/ubuntu \ $(lsb_release -cs) \ stable"
You can now install Docker from the new packages:
$ sudo apt-get install docker-ce
Finally, add your user to the docker group:
$ sudo usermod -a -G docker $USER
For more information, see Docker’s Install using the repository documentation.
Building with Docker
With Docker installed, first pull the latest snapcraft image:
$ docker pull snapcore/snapcraft
Make sure you’re in your project’s top-level directory, where snap/snapcraft.yaml describes how to build your snap, and enter the following command to build your snap:
$ docker run --rm -v "$PWD":/build -w /build snapcore/snapcraft bash \ -c "apt update && snapcraft"
That’s all there is to it. If the build completes successfully, you will find a
.snap file in the current directory. You can inspect its contents to ensure the snap contains all of your application’s assets:
$ unsquashfs -l *.snap
Last updated 2 months ago. Help improve this document in the forum.