How to upgrade an Ethereum Parity node in a few seconds using Docker
These days, you might find yourself in need to regularly update your Ethereum node. This article shows how to quickly do this running a Parity node running inside a Docker container.
Storing the blockchain data outside the Docker container is a necessary prerequisite, otherwise you will need to resync the blockchain after every upgrade, which takes time.
Boot your container with a command like this:
docker run -ti -d -v /var/parity/mainnet:/root/.parity \
-p 0.0.0.0:8545:8545 \
--name my-parity-node \
--restart always \
ethcore/parity:beta-release --jsonrpc-interface all \
--jsonrpc-hosts all
The -d flag has Docker container run in detached mode, in the background.
The -v is important. It mounts a directory of the host OS, /var/parity/mainnet in this case, inside the Docker container where it becomes available under /root/.parity, the default location for Parity to store the blocks and other stuff. Make sure the host directory exists and can be written to.
Also notice that we pull the ethcore/parity image by the tag beta-release. You can decide to go with the stable-release tag which will give you more stable releases, but less often.
Since we run Parity on a dedicated cloud VPS, we bind port 8545 to the loopback IP address using -p 0.0.0.0:8545:8545 to make it available to the outside world. You might want to change the portnumber to add some security by obscurity. In this case, add --rpcport [portnumber] to have the Parity RPC server listen on the same port.
Using Docker option --restart always ensures the container reboots in case of a node crash, which just so seems to happens once and a while.
To make make the PRC server available to the outside world, I also had to set --jsonrpc-interface and --jsonrpc-hosts to all.
PLEASE NOTE: If you are running this configuration on a public server, anyone can use your node. Be sure to never unlock an account on such node! See my previous article on Docker and Parity on how to restrict access.
Upgrading the node
With the blocks stored on the Docker host machine, upgrading becomes easy:
- Remove the local copy of the ethcore/parity image
- Pull the latest version of the image from Dockerhub.
- Stop and remove the Parity Docker container
- Run the above mentioned docker run command again.
The docker run will use the new image giving you the most recent version of Parity against a very short downtime.
docker rmi -f ethcore/parity:beta-release
docker pull ethcore/parity:beta-release
docker rm -f my-parity node
docker run -ti -d -v /var/parity/mainnet:/root/.parity \
-p 0.0.0.0:8545:8545 \
--name my-parity-node \
--restart always \
ethcore/parity:beta-release --jsonrpc-interface all \
--jsonrpc-hosts all
To get a list of all Parity’s options, run:
docker run ethcore/parity -h
You can check the Parity version of the latest Docker image you downloaded by issueing:
docker run ethcore/parity --version
To check the console output of the node, attach to the Docker container:
docker attach my-parity-node
Be sure the detach using Ctrl-P or Ctrl-Q otherwise you will stop the container (or merely reboot it if you specified the --restart always flag).
Script it!
It is a good idea to script the above commands. You might even want to put them in a cronjob to ensure you are always on the latest version.
My upgrade script looks like this:
#!/bin/bashecho '========= upgrading parities ============'
echo $(date)current=($(docker exec my-parity-node parity/target/release/parity --version))
current_version=${current[2]}
echo 'current version: '$current_versionecho 'refreshing ethcore/parity...'
docker rmi -f ethcore/parity:latest
docker pull ethcore/parity:latestnew=($(docker run ethcore/parity --version))
new_version=${new[2]}
echo 'remote version: '$new_versionif [ "$current_version" == "$new_version" ]; then
echo 'no upgrade detected, doing nothing';
else
docker rm -f my-parity node
docker run -ti -d -v /var/parity/mainnet:/root/.parity \
-p 0.0.0.0:8545:8545 \
--name my-parity-node \
--restart always \
ethcore/parity:latest --jsonrpc-interface all \
--jsonrpc-hosts all
fiecho '=== cleaning up stale images and containers ===='docker rm $(docker ps -qa --no-trunc --filter status=exited)
docker rmi $(docker images -q --filter dangling=true)echo '================= finished ==============='
To go to zero downtime, you could run two Docker containers on different RPC ports and reverse proxy them with a load balancer. With this in place, you can upgrade them one by one without downtime.
More information on Running Parity in Docker can be found in my previous article.
(Join the conversation on r/Ethereum)