Today we advise developers on Mac to build using snapcraft in Docker, but offer no way to test the resulting snap. A proper solution would involve LXD in a lightweight VM with an OSX-native snapcraft talking to that. However, I wanted to see if I could first get snapd inside a Docker for Mac container.
Unfortunately, that didn’t quite work:
$ cat Dockerfile
FROM ubuntu:16.04
ENV container docker
RUN apt-get update
RUN apt-get install -y snapd squashfuse
RUN systemctl enable snapd
STOPSIGNAL SIGRTMIN+3
CMD [ "/sbin/init" ]
Build it:
$ docker build -t snapd .
Run it:
$ docker run --name=snapdtest \
-ti --rm \
--tmpfs /run --tmpfs /run/lock \
--tmpfs /tmp --cap-add SYS_ADMIN --device=/dev/fuse \
--security-opt apparmor:unconfined \
-v /sys/fs/cgroup:/sys/fs/cgroup:ro -d \
snapd
Shell into it and try to install a snap:
$ docker exec -it snapdtest /bin/bash
$ snap install core
error: cannot perform the following tasks:
- Mount snap "core" (1577) ([start snap-core-1577.mount] failed with exit status 1: Job for snap-core-1577.mount
failed. See "systemctl status snap-core-1577.mount" and "journalctl -xe" for details.
)
$ systemctl status snap-core-1577.mount
● snap-core-1577.mount - Mount unit for core
Loaded: loaded (/etc/systemd/system/snap-core-1577.mount; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Thu 2017-04-06 08:47:53 UTC; 28s ago
Where: /snap/core/1577
What: /var/lib/snapd/snaps/core_1577.snap
Process: 2033 ExecMount=/bin/mount /var/lib/snapd/snaps/core_1577.snap /snap/core/1577 -t fuse.squashfuse -o ro,allow_other (code=exited, status=32)
Apr 06 08:47:53 968ad9239e74 systemd[1]: Mounting Mount unit for core...
Apr 06 08:47:53 968ad9239e74 mount[2033]: mount: wrong fs type, bad option, bad superblock on /var/lib/snapd/snaps/core_1577.snap,
Apr 06 08:47:53 968ad9239e74 mount[2033]: missing codepage or helper program, or other error
Apr 06 08:47:53 968ad9239e74 mount[2033]: In some cases useful info is found in syslog - try
Apr 06 08:47:53 968ad9239e74 mount[2033]: dmesg | tail or so.
Apr 06 08:47:53 968ad9239e74 systemd[1]: snap-core-1577.mount: Mount process exited, code=exited status=32
Apr 06 08:47:53 968ad9239e74 systemd[1]: Failed to mount Mount unit for core.
Apr 06 08:47:53 968ad9239e74 systemd[1]: snap-core-1577.mount: Unit entered failed state.
Skipping the mount call works [ed. clarifying: calling squashfuse
instead of mount -t fuse.squashfuse
]:
$ squashfuse -o ro,allow_other /var/lib/snapd/snaps/core_1577.snap /snap/core/1577
$ ls /snap/core/1577/
bin boot dev etc home lib lib64 media meta mnt opt proc root run sbin snap srv sys tmp usr var writable
$ uname -a
Linux 968ad9239e74 4.9.13-moby #1 SMP Sat Mar 25 02:48:44 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
Any ideas?