Shubham Chadokar
Software Engineer Specialist, Kaleyra
@schadokar1
How to Dockerize an Ethereum DAPP?
Shubham Chadokar
Software Engineer Specialist
@schadokar1
AGENDA
Learn Docker before learning web3
What is web3?
Why Docker for web3 development?
High Level Diagram
There are 3 parts of this DAPP
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;
}
}
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"]
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"]
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;"]
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
Demo
DockerHub
References
Contact Me
Thank You.