Simple Docker Image

Hey, guys have been playing around with Docker and it’s possible to create a lightweight Safe node using alpine (light Linux distro) and some dependencies + the installation script from the maidsafe GitHub.

Docker runs images inside of containers and this makes running it on any OS very simple. You only need to install docker which is widely available and optionally build from the source or download a generated docker image and directly run it. Some NAS like Synology also supports running docker images so it will directly spin up a Safe Node on your NAS if it supports it!

Steps to do:

  1. Install docker on your operating system
  2. Create a folder with a project name
  3. Copy the following code to the file that will be called ‘dockerfile’
# Build SafeNetwork Docker container
FROM alpine:latest
LABEL version="0.1"
LABEL maintainer="DeusNexus"
LABEL release-date="2021-01-31"

# Update and install dependencies
RUN apk update
RUN apk add bash #unix shell to run install script
RUN apk add curl #cUrl to transfer data

#Make profile file with exported PATH and refresh the shell (while building)
SHELL ["/bin/bash", "--login", "-c"]
RUN echo 'export PATH=$PATH:/root/.safe/cli' > ~/.profile && source ~/.profile

#Set ENV PATH (after build will be used to find 'safe')
ENV PATH=$PATH:/root/.safe/cli

#Installation Script - MaidSafe installation script
RUN curl -so- https://sn-api.s3.amazonaws.com/install.sh | bash

#Install Safe - During Build
RUN safe node install
RUN safe auth install

#Expose PORT of the node 
EXPOSE 12000

#Run command on Docker launch
CMD ["safe"]
  1. Build the docker image with docker build -t safe_node . while in the project folder with the dockerfile (My image is built with Docker version 20.10.2, build 2291f61)

This will download all the dependencies and use the installation script to install safe.

  1. After the image is built you can spin it up any time using docker run -it safe_node.
    It will open up into the safe_cli interface, you can use --help to see the commands. Just note that I’m still fixing some bugs bug in general it seems to be decently working.

Things to add are a VOLUME basically the external mounting point that the docker image will use to store data and make the data persistent!

Cool things possible to add are simple HTTP GUI that could restart the server with buttons, display the state, and various things using express server and exposed apache server.

25 Likes

hmhmmm we should push that to dockerhub :thinking:

so that a simple

docker run -it -p 12000:12000 -e PATH:/root/.safe/cli safe-node:v0.0.0

is enough to start it and start playing with it :open_mouth:

…but together with a Warning/Hint that this is

  1. not yet production ready and in experimental state
  2. the network itself is still in alpha and the coins are not the final safecoin
6 Likes

Nice work @DeusNexus! Docker containers are super handy for stuff like this.

6 Likes

hmhmmm - do nodes right now always use this port? or was this an example? (i thought they’re supposed to use random ports?)

2 Likes

I get an error for line 13 at docker build -t safe_node .

SHELL requires the arguments to be in JSON form

SHELL ["/bin/bash", “–login”, “-c”]

PS note that trailing dot on the build -t safe_node . command - it matters

Login should be “–login” (dash-dash)

1 Like

Interesting! I will try this with Podman when I get a chance . .

Yes I have seen that error before when cut n pasting from the screen - As ever I forget about it until reminded - thank you

I’m still getting the JSON error though

➜  docker docker build -t safe_node .
Sending build context to Docker daemon   2.56kB
Error response from daemon: Dockerfile parse error line 13: SHELL requires the arguments to be in JSON form
➜  docker

@DeusNexus you should put the stuff from “Copy the following code to the file that will be called ‘dockerfile’” inside of a code block in your post, like this:

```text
All my
Nice text
```

Becomes

All my
Nice text

This prevents Discourse from doing formatting on the text, in this case for instance “--” became “–” which broke the script when copied and pasted.

5 Likes

Maybe try to download the latest version of docker or remove the --login and see if it does the trick?

1 Like

I updated it now! Thanks for the tip.

1 Like

checkout Hermitux/Hermitcore Unikernel from Virginia Tech Uni , supports K or Docker container provisioning. You will need to re-package to include all the libs required by the Safenode, you can run the binary of the node as is , uses ‘trampoline’ jmp to replace all relevant syscalls to the libs in question, meaning you can load any app binary in the container at just runs provided you re-package w/ requisite libs for the app your loading …, very lean, supports Intel AMD64 or ARM64 which means in the latter case you can get it to run on RapsberryPi or Beagle or similar…

Linux Ubuntu 18.04 … last time I looked

Not for the technically meek :wink:

r2

1 Like

Pretty sure this is the latest version

willie@gagarin:~$ docker -v
Docker version 20.10.2, build 2291f61

Can someone who has made this work please reply with their exact configuration and Dockerfile please?

What kind of error are you getting? Is it still saying you need to provide a JSON array of arguments?
Take note I also still get some error while trying to run the authd but the safe cli interface with commands is working.

1 Like

yep 10 char

But Just Works on the laptop - no issues at all weird…