Sinay
Sinay

Reputation: 317

Dockerfile, how install snap, snapd: unrecognized service

well I got some problem with my Dockerfile, in fact I try to install snapd on Debian and Ubuntu in almost all version.

When I try to launch a command I got this error

error: cannot communicate with server: Post http://localhost/v2/snaps/rocketchat-server: dial unix /run/snapd.socket: connect: no such file or directory

So I tried to see if the service is enabled, and there is no service called snapd, even if I try to start with systemctl systemctl start snapd, I have an error

Failed to connect to bus: No such file or directory

so I installed dbus, and when I try again now I have this error

Failed to start snapd.service: Launch helper exited with unknown return code 1

I tried to start the service with service or journalctl and it shows

snapd: unrecognized service

When I list all my services I have this

 [ - ]  apparmor

 [ - ]  bootmisc.sh

 [ - ]  checkfs.sh

 [ - ]  checkroot-bootclean.sh

 [ - ]  checkroot.sh

 [ + ]  dbus

 [ - ]  hostname.sh

 [ ? ]  hwclock.sh

 [ - ]  killprocs

 [ - ]  mountall-bootclean.sh

 [ - ]  mountall.sh

 [ - ]  mountdevsubfs.sh

 [ - ]  mountkernfs.sh

 [ - ]  mountnfs-bootclean.sh

 [ - ]  mountnfs.sh

 [ ? ]  ondemand

 [ - ]  procps

 [ - ]  rc.local

 [ - ]  sendsigs

 [ + ]  udev

 [ - ]  umountfs

 [ - ]  umountnfs.sh

[ - ]  umountroot

 [ - ]  urandom

FROM ubuntu:16.04

RUN apt-get update && apt-get -y upgrade &&\
    apt-get install -y snap snapd

RUN snap install rocketchat-server
#"error: cannot communicate with server: Post #http://localhost/v2/snaps/rocketchat-server: dial unix #/run/snapd.socket: connect: no such file or directory"

RUN snap --version
#snap    2.40
#snapd   unavailable
#series  -

EXPOSE 3000

ENTRYPOINT Server is running .... && tail -f /dev/null

I know that with docker playing with service is not good but I don't know how can I improve my Dockerfile, I begin with rocketchat doc debian, then ubuntu, then snap (because its easier), and with all of them I got this error.

Upvotes: 31

Views: 35385

Answers (4)

Iman Kermani
Iman Kermani

Reputation: 939

If you are using WSL2 you can overcome this problem by adding the following line in /etc/wsl.conf:

[boot]
systemd=true

Don't forget to restart WSL using PowerShell:

wsl.exe --shutdown
wsl.exe

Upvotes: 0

nicht-vergessen
nicht-vergessen

Reputation: 375

first of all, you don't want to install the "snap" package, as it is not related to "snapd". Secondly, myself stumbled across this issue of installing snapd within a docker container: TLDR; Running snapd that way is currently not supported.

But that question has been asked already at the snapcraft forums. One of snapd's dependencies is systemd and the snapd-service isn't properly initialized without a reboot or relogin. That is the required procedure according to the documentation across all distributions, but obviously isn't an option within docker.

At least this open question replicates your question most: unable-to-install-snapcraft-snap-in-docker-image-ubuntu-19-10

And Evan at the snapcraft forum here posted an approach, that I couldn't get to work either.

The only approach that might work is similar to running docker inside of docker, i.e.:

  • install snapd on the docker host
  • mount the snapd-socket at runtime into the container that has snapd installed.

But same warnings/side-effects apply as they do to running docker-in-docker.

Upvotes: 24

TudorIftimie
TudorIftimie

Reputation: 1140

I had a similar issue on GCP's dedicated os for containers. This is how it worked for me (based on the Joseph Lust's reply):

Before you start:

  • Make sure the DNS is pointing to your VM external IP
  • make sure that anyone can access port 80
  • stop the container with your app if it is using port 80 (certbot container will create a http server on port 80)

Run the certbot container:

sudo docker run -it --rm --name certbot \
            -v "/etc/letsencrypt:/etc/letsencrypt" \
            -v "/var/lib/letsencrypt:/var/lib/letsencrypt" \
            -p 80:80 \
            certbot/certbot certonly

Select option 1 and then input your domain. (Would be nice to find a way to automate this ... )

Start your container with mounted volumes for :

        -v "/etc/letsencrypt:/etc/letsencrypt" 
        -v "/var/lib/letsencrypt:/var/lib/letsencrypt"

Upvotes: 1

Joseph Lust
Joseph Lust

Reputation: 19995

I ran into this problem too, but was able to use the EFF's prebuilt Certbot images on DockerHub

FROM certbot/certbot:latest (see all tags)

Upvotes: 4

Related Questions