README.md 3.8 KB
Newer Older
S
Sandwich 已提交
1
# Run in docker
N
Nathan Hourt 已提交
2

K
Kevin Heifner 已提交
3
Simple and fast setup of EOS.IO on Docker is also available.
S
Sandwich 已提交
4 5

## Install Dependencies
6 7 8

- [Docker](https://docs.docker.com) Docker 17.05 or higher is required
- [docker-compose](https://docs.docker.com/compose/) version >= 1.10.0
peterwillcn's avatar
peterwillcn 已提交
9

A
Andrianto Lie 已提交
10
## Docker Requirement
11 12

- At least 8GB RAM (Docker -> Preferences -> Advanced -> Memory -> 8GB or above)
N
noprom 已提交
13

S
Sandwich 已提交
14
## Build eos image
peterwillcn's avatar
peterwillcn 已提交
15

S
Sandwich 已提交
16
```bash
peterwillcn's avatar
peterwillcn 已提交
17
git clone https://github.com/EOSIO/eos.git --recursive
H
Huang-Ming Huang 已提交
18 19
cd eos/Docker
docker build . -t eosio/eos
peterwillcn's avatar
peterwillcn 已提交
20 21
```

22
## Start nodeos docker container only
peterwillcn's avatar
peterwillcn 已提交
23

S
Sandwich 已提交
24
```bash
peterwillcn's avatar
peterwillcn 已提交
25
docker run --name nodeos -p 8888:8888 -p 9876:9876 -t eosio/eos nodeosd.sh arg1 arg2
peterwillcn's avatar
peterwillcn 已提交
26
```
S
Sandwich 已提交
27

H
Huang-Ming Huang 已提交
28
By default, all data is persisted in a docker volume. It can be deleted if the data is outdated or corrupted:
29 30

```bash
31
$ docker inspect --format '{{ range .Mounts }}{{ .Name }} {{ end }}' nodeos
H
Huang-Ming Huang 已提交
32 33 34
fdc265730a4f697346fa8b078c176e315b959e79365fc9cbd11f090ea0cb5cbc
$ docker volume rm fdc265730a4f697346fa8b078c176e315b959e79365fc9cbd11f090ea0cb5cbc
```
H
Huang-Ming Huang 已提交
35

H
Huang-Ming Huang 已提交
36
Alternately, you can directly mount host directory into the container
37

H
Huang-Ming Huang 已提交
38
```bash
peterwillcn's avatar
peterwillcn 已提交
39
docker run --name nodeos -v /path-to-data-dir:/opt/eosio/bin/data-dir -p 8888:8888 -p 9876:9876 -t eosio/eos nodeosd.sh arg1 arg2
H
Huang-Ming Huang 已提交
40 41
```

S
Sandwich 已提交
42 43 44
## Get chain info

```bash
peterwillcn's avatar
peterwillcn 已提交
45
curl http://127.0.0.1:8888/v1/chain/get_info
peterwillcn's avatar
peterwillcn 已提交
46 47
```

48
## Start both nodeos and keosd containers
H
Huang-Ming Huang 已提交
49 50

```bash
N
noprom 已提交
51
docker volume create --name=nodeos-data-volume
52
docker volume create --name=keosd-data-volume
N
noprom 已提交
53
docker-compose up -d
H
Huang-Ming Huang 已提交
54 55
```

56
After `docker-compose up -d`, two services named `nodeosd` and `keosd` will be started. nodeos service would expose ports 8888 and 9876 to the host. keosd service does not expose any port to the host, it is only accessible to cleos when runing cleos is running inside the keosd container as described in "Execute cleos commands" section.
H
Huang-Ming Huang 已提交
57

58
### Execute cleos commands
peterwillcn's avatar
peterwillcn 已提交
59

60
You can run the `cleos` commands via a bash alias.
S
Sandwich 已提交
61 62

```bash
63
alias cleos='docker-compose exec keosd /opt/eosio/bin/cleos -H nodeosd'
64 65
cleos get info
cleos get account inita
peterwillcn's avatar
peterwillcn 已提交
66 67
```

H
Huang-Ming Huang 已提交
68 69
Upload sample exchange contract

S
Sandwich 已提交
70
```bash
71
cleos set contract exchange contracts/exchange/exchange.wast contracts/exchange/exchange.abi
peterwillcn's avatar
peterwillcn 已提交
72 73
```

74
If you don't need keosd afterwards, you can stop the keosd service using
S
Sandwich 已提交
75 76

```bash
77
docker-compose stop keosd
H
Huang-Ming Huang 已提交
78
```
79

H
Huang-Ming Huang 已提交
80
### Change default configuration
H
Huang-Ming Huang 已提交
81 82 83 84 85 86 87

You can use docker compose override file to change the default configurations. For example, create an alternate config file `config2.ini` and a `docker-compose.override.yml` with the following content.

```yaml
version: "2"

services:
88
  nodeos:
H
Huang-Ming Huang 已提交
89
    volumes:
90
      - nodeos-data-volume:/opt/eosio/bin/data-dir
K
Kevin Heifner 已提交
91
      - ./config2.ini:/opt/eosio/bin/data-dir/config.ini
S
Sandwich 已提交
92 93
```

H
Huang-Ming Huang 已提交
94
Then restart your docker containers as follows:
S
Sandwich 已提交
95 96

```bash
H
Huang-Ming Huang 已提交
97 98 99
docker-compose down
docker-compose up
```
H
Huang-Ming Huang 已提交
100 101

### Clear data-dir
102

H
Huang-Ming Huang 已提交
103 104 105
The data volume created by docker-compose can be deleted as follows:

```bash
106 107
docker volume rm nodeos-data-volume
docker volume rm keosd-data-volume
H
Huang-Ming Huang 已提交
108
```
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145

### More easily mode

 Sometimes, it's still hard for you to build it locally, for some reasons such as bad network, not strong enough cpu, and so on, and then you can use the image from [docker hub](https://hub.docker.com/r/eosio/eos/).
Just replace the `docker-compose.yaml` file with the content below

```bash
version: "3"

services:
  nodeosd:
    image: eosio/eos:latest
    command: /opt/eosio/bin/nodeosd.sh
    hostname: nodeosd
    ports:
      - 8888:8888
      - 9876:9876
    expose:
      - "8888"
    volumes:
      - nodeos-data-volume:/opt/eosio/bin/data-dir

  keosd:
    image: eosio/eos:latest
    command: /opt/eosio/bin/keosd
    hostname: keosd
    links:
      - nodeosd
    volumes:
      - keosd-data-volume:/opt/eosio/bin/data-dir

volumes:
  nodeos-data-volume:
  keosd-data-volume:

```

K
kaidiren 已提交
146 147 148 149
*NOTE:* the defalut version is the latest, you can change it to what you want

run `docker pull eosio/eos:latest` 

150 151
run `docker-compose up`

K
kaidiren 已提交
152
and  enjoy it.