diff --git a/.gitignore b/.gitignore index 4969d2e6f18129607f8d7522148a335adffef417..dee6ee1991cf5af01032e2231f2afb0be23c517f 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,10 @@ # These are backup files generated by rustfmt **/*.rs.bk -.DS_Store \ No newline at end of file +.DS_Store + +# The cache for docker container dependency +.cargo + +# The cache for chain data in container +.local \ No newline at end of file diff --git a/README.md b/README.md index d3502ccb400d6177c6f8be95be2b10302b8ce207..475444ad2019d49ae44e48a4d0e62df624490f0e 100644 --- a/README.md +++ b/README.md @@ -80,6 +80,32 @@ cargo run -- \ Additional CLI usage options are available and may be shown by running `cargo run -- --help`. +### Run in Docker + +Install [Docker](https://docs.docker.com/get-docker/) first, then run the following command to start a single node development chain. This command will firstly comipile your code, then start a local dev netork. + +```bash +./scripts/docker_run.sh +``` + +If you just want to run the compiled binary, + +```bash +./scripts/docker_run.sh ./target/release/node-template --dev --ws-external +``` + +Other commands are similar. Let's try purge the local dev chain here: + +```bash +./scripts/docker_run.sh ./target/release/node-template purge-chain --dev +``` + +You can also check whether the code is able to compile or not, + +```bash +./scripts/docker_run.sh cargo check +``` + ## Advanced: Generate Your Own Substrate Node Template A substrate node template is always based on a certain version of Substrate. You can inspect it by diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000000000000000000000000000000000000..494c0a0155f12c63f8d9b84b94880f68e890e8de --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,17 @@ +version: "3.2" + +services: + dev: + container_name: node-template + image: parity/rust-builder:latest + working_dir: /var/www/node-template + ports: + - "9944:9944" + environment: + - CARGO_HOME=/var/www/node-template/.cargo + volumes: + - .:/var/www/node-template + - type: bind + source: ./.local + target: /root/.local + command: bash -c "cargo build --release && ./target/release/node-template --dev --ws-external" diff --git a/scripts/docker_run.sh b/scripts/docker_run.sh new file mode 100755 index 0000000000000000000000000000000000000000..61e6b0fd162fc8673027e9a3bc163b539e31859b --- /dev/null +++ b/scripts/docker_run.sh @@ -0,0 +1,10 @@ +#!/usr/bin/env bash + +set -e + +echo "*** Start Substrate node template ***" + +cd $(dirname ${BASH_SOURCE[0]})/.. + +docker-compose down --remove-orphans +docker-compose run --rm --service-ports dev $@ \ No newline at end of file