Hi all,
I’m new to Snap and trying to create a snap that pulls and run my Docker image on Docker.
And if it possible to bundle the Docker inside the snap so the users won’t need to install Docker or know it’s necessary.
Do you have some examples that I can look as a reference?
Additionally, I found 2 interfaces relevant to Docker: docker interface and docker-support interface.
But I can’t understand from the description what can I perform with each one of them. Can you elaborate more details?
You should not need to use the docker-support interface at all. The docker interface will provide access to the Docker daemon socket to allow you to start and stop containers. You will need to either use the docker-executables content interface from the Docker snap or ship the relevant utilities or libraries you need to interact with Docker. An example of using the docker-executables interface is below (though I haven’t tested the correctness of it you should get a good idea of how it works):
Found the following dockerized-app-snap repository on GitHub which really helped me to create a Snap that run a dockerzied app through the content-interface shared by the docker snap.
Attached my snapcraft.yaml for anyone who trying to do something similar:
You can find general explanation on Snap Interfaces(plugs and slots) here In short, an interface consists of a connection between a slot and a plug. The slot is the provider of the interface while the plug is the consumer. In my case, the docker snap has 2 interfaces that it provides(slots) which my-app consumes(plugs) - the docker interface under the docker-cli plug and the content interface under docker-executables plug.
Regarding the question if Docker must be installed via Snap. Because my-app snap uses the docker snap interfaces, the answer it yes. But I’m not sure if it’s conflict with a docker installed on the machine. will update when I have the answer.
> snap run --shell dotrun
$ /snap/dotrun/current/docker-env/bin/docker images
Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get http://%2Fvar%2Frun%2Fdocker.sock/v1.39/images/json: dial unix /var/run/docker.sock: connect: permission denied
Any idea why I’m getting permission denied? Is there a connection I’m missing? I couldn’t work out how to connect the docker/docker-cli interface to anything.
Worked, thanks. Should we add this to documentation somewhere? The only mention of the docker interface I found in the docs is incredibly sparse - doesn’t mention docker-executables or docker-daemon.
We do not have official docs on using the docker snap this way (or should not to my knowledge). I think a forum post is more appropriate for this information. BTW, I have an unofficial example of a snap doing this that could be used for an example: https://github.com/anonymouse64/docker-snap-usage-example
@ijohnson Do you know what could be the reason docker-compose is not working?
$ snap run --shell dotrun
To run a command as administrator (user "root"), use "sudo <command>".
See "man sudo_root" for details.
$ /snap/dotrun/current/docker-env/bin/docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
$ /snap/dotrun/current/docker-env/bin/docker-compose
Traceback (most recent call last):
File "/snap/dotrun/current/docker-env/bin/docker-compose", line 33, in <module>
sys.exit(load_entry_point('docker-compose==1.25.5', 'console_scripts', 'docker-compose')())
File "/snap/dotrun/current/docker-env/bin/docker-compose", line 22, in importlib_load_entry_point
for entry_point in distribution(dist_name).entry_points
File "/snap/dotrun/x1/lib/python3.6/site-packages/importlib_metadata/__init__.py", line 558, in distribution
return Distribution.from_name(distribution_name)
File "/snap/dotrun/x1/lib/python3.6/site-packages/importlib_metadata/__init__.py", line 215, in from_name
raise PackageNotFoundError(name)
importlib_metadata.PackageNotFoundError: No package metadata was found for docker-compose