Install snap in Docker

I try to install snap in a Docker container. The OS is CentOS 8. For a project I have to use the Mumble client. The idea is to install snap and mumble in a Docker container .

I use the post as a template for my Docker file.
Snapd in Docker

I get this error message:

Step 7/9 : RUN systemctl enable --now snapd.socket
 ---> Running in 4271707f5477
Created symlink /etc/systemd/system/ → /usr/lib/systemd/system/snapd.socket.
System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to connect to bus: Host is down
The command '/bin/sh -c systemctl enable --now snapd.socket' returned a non-zero code: 1

here is the Dockerfile

FROM centos:latest

ENV container docker
ENV PATH /snap/bin:$PATH
ADD snap /usr/local/bin/snap

RUN dnf update -y  \
    && dnf install -y epel-release \
    && dnf install -y snapd \
    && dnf clean all \
    && rm -rf /var/cache/dnf

RUN systemctl enable --now snapd.socket
RUN ln -s /var/lib/snapd/snap /snap

CMD [ "/sbin/init" ]

It is not possible to run snapd inside a container, is there any problem why it can’t be installed directly on the host system?

Please read this

$ cat Dockerfile
FROM ubuntu:16.04
ENV container docker
ENV PATH /snap/bin:$PATH
ADD snap /usr/local/bin/snap
RUN apt-get update
RUN apt-get install -y snapd squashfuse fuse
RUN systemctl enable snapd
CMD [ "/sbin/init" ]


$ cat snap
#!/bin/sh -e

while ! kill -0 $(pidof snapd) 2>/dev/null; do
  echo "Waiting for snapd to start."
  sleep 1

/usr/bin/snap $@

$ chmod +x snap

Now, build it:

$ docker build -t snapd . 

Run it:

$  docker run --name=snapd -ti -d \                                                                                     
  --tmpfs /run --tmpfs /run/lock --tmpfs /tmp \
  --privileged \ # [1]
  -v /lib/modules:/lib/modules:ro \ # [2]

And install some snaps:

$ docker exec -it snapd snap install emoj
$ docker exec -it snapd emoj success
✔  ✅  ☑  📚  👌  🎓  💰


  1. Otherwise systemd complains about /sys not being writable when reloading udev rules (ConditionPathIsReadWrite=/sys was not met)
  2. Otherwise strictly confined snaps fail to execute:
    $ docker exec -it snapd emoj
    cannot perform operation: mount --rbind /lib/modules /tmp/snap.rootfs_NCx2ET//lib/modules: No such file or directory

I don’t use centos, but looking to do similar on Arch for CI purposes.

I stumbled across this which seems promising.

I’m immediately running into issues with your Dockerfile before getting to Step 7, but it might help. I’m still having issues myself, but I’m getting some systemctl functionality.

If you’d like a reference (and I would not recommend this implementation for a production application),