'snap and gitlab-CI: error: cannot communicate with server: Post http://localhost/v2/snaps/hello-world
If I try to run snap under a gitlab-CI pipeline, installing the most simple package, it fails with:
$ snap install hello-world
error: cannot communicate with server: Post http://localhost/v2/snaps/hello-world: dial unix /run/snapd.socket: connect: no such file or directory
The gitlab-ci yml configuration file is the simplest ever:
image: ubuntu:18.04
before_script:
- apt-get update -qq
test:
script:
- apt-get install -y snapd
- snap version
- snap install hello-world
- hello-world
What's going on?
Solution 1:[1]
Seems GithubActionsCI doesn't use Docker so I'm using this now instead of GitLabCI, to build and test snap packages.
Just note:
- You need sudo to install snap with apt-get, and also to install any snap package with the snap command.
- If you want to run the
snapcraft(to build packages, not just test them), getting it viaapt-getworks, but gives a version that is a bit old (e.g. it doesn't support layouts). If you want a newer version, you can install it via snap withsnap install snapcraftbut you need some workarounds to make it run, such assudo chown root:root /and to pass the--destructive-modeflag (see https://forum.snapcraft.io/t/permissions-problem-using-snapcraft-in-azure-pipelines/13258/16).
Solution 2:[2]
In my case it is solved by starting the snapd service:
systemctl start snapd.service
Solution 3:[3]
Unfortunately, snaps use many of the underlying security tech used by docker, and they don't play very nicely. Installing a snap also requires snapd to be running, which it's not in docker (hence the error). I'm afraid you simply cannot reliably install snaps in docker containers today.
Note that there are other non-docker-based CI systems. You can, with a little custom work, use LXD as the backend for your GitLab CI runner, which handle snaps fine. You can also use GitHub Actions, which seem so be based on a Azure VM, which also handles snaps fine.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 | Simon |
| Solution 3 |
