1 of 17

Shubham Chadokar

Software Engineer Specialist, Kaleyra

@schadokar1

2 of 17

How to Dockerize an Ethereum DAPP?

Shubham Chadokar

Software Engineer Specialist

@schadokar1

3 of 17

4 of 17

AGENDA

  1. What is Web3?
  2. Why Docker for web3 development?
  3. High Level Diagram of Ethereum DAPP
  4. Writing Dockerfiles and building images
  5. Demo
  6. Push images to Docker Hub

5 of 17

Learn Docker before learning web3

6 of 17

What is web3?

  • At Core, it is a Decentralised Internet.
  • Implementation using Blockchain or distributed network.
  • For Ex. Bitcoin, Ethereum, Corda.
  • DAPP: Decentralised Application

7 of 17

Why Docker for web3 development?

  • Many blockchains works on specific versions. OS, libraries
  • It is not ideal to setup multiple VMs to work with different blockchains due to their resp system requirement.

8 of 17

High Level Diagram

There are 3 parts of this DAPP

  • Local Blockchain (Local DB)
  • Nodejs Server (Interface)
  • Reactjs Application

9 of 17

Smart Contract

pragma solidity ^0.4.25;

contract Message {

string public message;

constructor(string memory _message) public {

message = _message;

}

function setMessage (string memory _newMessage) public {

message = _newMessage;

}

function getMessage() public view returns(string memory) {

return message;

}

}

10 of 17

Ganache Dockerfile

# base image - node:alpine

FROM node:14.19.1-alpine

# set the working directory to /app

WORKDIR /app

# install ganache-cli globally

RUN npm install -g ganache-cli

# set the command ganache-cli -h 0.0.0.0

# for docker ganache-cli host on 0.0.0.0

CMD ["ganache-cli","-h","0.0.0.0"]

11 of 17

Server Dockerfile

# using node alpine as base image

FROM node:8.12-alpine

# working dir ./app

WORKDIR /app

# Install the prerequisites to install the web3 and other ethereum npm packages

RUN apk update && apk upgrade && apk add bash git openssh

RUN apk add --update python2 krb5 krb5-libs gcc make g++ krb5-dev

RUN git config --global url."https://".insteadOf git://

# Copy the package.json

COPY ./package.json .

# Install the dependencies

RUN npm install

# Copy the server and ethereum module

COPY . .

# set the default command

CMD ["npm","start"]

12 of 17

Reactjs Dockerfile

# STAGE 1: using node alpine as base image

FROM node:12-alpine as build

# working dir ./app

WORKDIR /app

# Copy react package.json

COPY ./package.json .

# install dependencies

RUN npm install --silent

# COPY client directory folder

COPY . .

# default command

RUN npm run build

### STAGE 2: Production Environment ###

FROM nginx:1.21.6-alpine

COPY --from=build /app/build /usr/share/nginx/html

EXPOSE 80

CMD ["nginx", "-g", "daemon off;"]

13 of 17

Docker Compose

version: "3"

services:

ganache:

image: schadokar/eth-ganache:1.0.0

build:

context: .

dockerfile: Dockerfile.ganache

ports:

- "8545:8545"

dapp:

image: schadokar/eth-server:1.0.0

build: .

ports:

- "4000:4000"

depends_on:

- ganache

react:

image: schadokar/eth-react:1.0.0

build: ./client

ports:

- "3000:80"

depends_on:

- dapp

14 of 17

Demo

15 of 17

DockerHub

16 of 17

References

Contact Me

17 of 17

Thank You.