Skip to content

Commit

Permalink
Docker node
Browse files Browse the repository at this point in the history
- Restart on crash
- Wallet and account setup via CLI (because you need that anyway for the seed)
- RPC sample
- Updating
- Bash alias via container name
- Formatting
  • Loading branch information
BitDesert committed May 11, 2018
1 parent d473b0b commit c0c83b8
Showing 1 changed file with 79 additions and 22 deletions.
101 changes: 79 additions & 22 deletions Docker-node.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,32 @@
The fastest way to set up a Nano node is via a docker container from DockerHub. You'll need a semi-recent version of docker, Client Version ~ 1.5.0.
[![Docker Pulls](https://img.shields.io/docker/pulls/nanocurrency/nano.svg)](https://hub.docker.com/r/nanocurrency/nano/)

The fastest way to set up a Nano node is via a docker container from DockerHub. You'll need a semi-recent version of Docker, Client Version ~ 1.5.0.

### Installation instructions

https://docs.docker.com/engine/installation

### Pulling docker image
### Pulling Docker image

```bash
sudo docker pull nanocurrency/nano
```
```

### Running

```bash
sudo docker run -d -p 7075:7075/udp -p 7075:7075 -p [::1]:7076:7076 -v ~:/root nanocurrency/nano
sudo docker run -d -p 7075:7075/udp -p 7075:7075 -p [::1]:7076:7076 -v ~:/root --restart=unless-stopped nanocurrency/nano

This comment has been minimized.

Copy link
@PlasmaPower

PlasmaPower May 11, 2018

Contributor

Does unless-stopped include reboots?

This comment has been minimized.

Copy link
@BitDesert

BitDesert May 12, 2018

Author Owner

Yes, unless you manually stop the container. According to Docker Docs:

Always restart the container regardless of the exit status, including on daemon startup, except if the container was put into a stopped state before the Docker daemon was stopped.

https://docs.docker.com/engine/reference/run/#restart-policies---restart

This comment has been minimized.

Copy link
@PlasmaPower

PlasmaPower May 12, 2018

Contributor

Should we explicitly name the container here? e.g. --name nano-node.

This comment has been minimized.

Copy link
@BitDesert

BitDesert May 12, 2018

Author Owner

No, imo that's not necessary. We shouldn't predefine a name.

A small example is available at Usability on the bottom of the page.

```

This command:
* Starts the docker container as a daemon "-d"
* Maps the network activity port "-p 7075:7075/udp"
* Maps the bootstrapping TCP port "-p 7075:7075"
* Maps the RPC control port to the local adapter only "-p [::1]:7076:7076"
* Maps the host's home directory to the guest /root directory "~:/root"
* Specifies the container to execute "nanocurrency/nano"

* Starts the docker container as a daemon `-d`
* Maps the network activity port `-p 7075:7075/udp`
* Maps the bootstrapping TCP port `-p 7075:7075`
* Maps the RPC control port to the local adapter only `-p [::1]:7076:7076`
* Maps the host's home directory to the guest /root directory `~:/root`
* Restarts the container if it crashes `--restart=unless-stopped`
* Specifies the container to execute `nanocurrency/nano`

This will put the data in a permanent location in your hosts's home directory, outside the docker container.

Expand All @@ -33,32 +38,84 @@ If you get `create ~: volume name is too short, names should be at least two alp

### Setting up a wallet and adding accounts

`curl -d '{ "action" : "wallet_create" }' [::1]:7076`
The response will look like:
`{ "wallet" : "000D1BAEC8EC208142C99059B393051BAC8380F9B5A2E6B2489A277D81789F3F" }`
The number is the wallet ID that you can use to reference this wallet in other API commands.
You'll need the container ID for the following commands. You can get it with `sudo docker ps` e.g. `d9416b274092`. Replace `<CONTAINERID>` with that ID.

First create a new wallet:

```bash
sudo docker exec <CONTAINERID> /usr/bin/rai_node --wallet_create

This comment has been minimized.

Copy link
@baryluk

baryluk May 30, 2018

Please drop all sudo everywhere. On most systems you can use docker as a normal user without problems, and it makes much more sense.

This comment has been minimized.

Copy link
@PlasmaPower

PlasmaPower May 30, 2018

Contributor

Actually it makes less sense. From the Arch wiki:

Warning: Anyone added to the docker group is root equivalent. More information here and here.

```

You should get a wallet ID which you need in the next step.

```bash
sudo docker exec <CONTAINERID> /usr/bin/rai_node --account_create --wallet=<WALLETID>
```

You get a new Nano address starting with xrb_1234… back.

To get your seed execute:

```bash
sudo docker exec <CONTAINERID> /usr/bin/rai_node --wallet_decrypt_unsafe --wallet=<WALLETID>
```

More information about the wallet backup is available here: [Wallet Backups](https://github.com/nanocurrency/raiblocks/wiki/Wallet-Backups)

### RPC interface

You can use the RPC interface on the local host via `curl`.

`curl -d '{ "action": "account_create", "wallet": "000D1BAEC8EC208142C99059B393051BAC8380F9B5A2E6B2489A277D81789F3F" }' [::1]:7076`
The response will look like:
`{ "account" : "xrb_3e3j5tkog48pnny9dmfzj1r16pg8t1e76dz5tmac6iq689wyjfpi00000000" }`
This is the account number that was just created.
For example the version of the node:

Back up the wallet seed following the backup instructions https://github.com/nanocurrency/raiblocks/wiki/Wallet-Backups
```bash
curl -d '{ "action" : "version" }' [::1]:7076
```

Or the blockcount:

```bash
curl -d '{ "action" : "block_count" }' [::1]:7076
```

All available RPC commands are listed here: [RPC protocol](https://github.com/nanocurrency/raiblocks/wiki/RPC-protocol)

### Updating

To update your container you need to rebuild it.

**Make sure that you have your seed backup up!**

First stop your old container:

```bash
sudo docker stop <CONTAINERID>
```

Then remove it:

```bash
sudo docker rm <CONTAINERID>
```

Then pull the new image and run the image just like you did at first start.

### Usability

You can find reference material for using docker here: https://docs.docker.com/engine/reference/commandline/

You can create a custom name for your container at the `docker run`command by adding e.g. `--name nanonode`.

Once set up, using bashrc to create an alias can save you time.

For example (when 97bf54657cdb is your docker container):
For example (when `nanonode` is the name your docker container):

`sudo docker exec 97bf54657cdb /usr/bin/rai_node --diagnostics`
`sudo docker exec nanonode /usr/bin/rai_node --diagnostics`

Can be shortened to:

`rai --diagnostics`

By editing ~/.bashrc to add the alias:

`alias rai='sudo docker exec 97bf54657cdb /usr/bin/rai_node'`
`alias rai='sudo docker exec nanonode /usr/bin/rai_node'`

3 comments on commit c0c83b8

@PlasmaPower
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wallet changes from the CLi require the node to restart before the changes take effect. I'd recommend sticking with the RPC for that reason (or at least document the need to restart).

@BitDesert
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do they behave differently? Added the restart command at 5f8dd90

@PlasmaPower
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The wallets are stored in memory, because they need to store things like the unencrypted key. We might change that in the future though (e.g. if a wallet doesn't exist in memory, query it from the DB).

Please sign in to comment.