Docker on the Educative Platform

We use Docker to allow authors to create their own custom environments to accommodate any language that is not supported by our platform.

Authors can create custom docker images that deploy on the Google Cloud and allow end-users to directly have access to these customized environments through our platform.

The Jargon

Base Image: An OS userspace.

Image: A read-only template with instructions for creating a Docker container.

Dockerfile: A simple file with no extension, named Dockerfile is used to builds a Docker image, and specifies everything that will go in the application’s environment setup.

Container: An image when run, builds a container. This contains your application environment, basically where your application will be run.

Tarball

Press + to interact
-tarball
--Dockerfile
--[OTHER FILES]

The above shows the directory structure of our tarball.

The command to create this tarball is as follows:

Press + to interact
tar -czpf ethereum.tar.gz Dockerfile .

As you can see, the Dockerfile must be nested directly inside the tarball (not inside any child folder).

This allows Educative to access the Dockerfile directly and create a docker container for our application’s environment.

Points to Note:

  • All files can be found for download in the Appendix of this lesson.
  • Only ONE tarball can be uploaded and used at a time. Uploading a new tarball will replace any previously uploaded.

Dockerfile

Press + to interact
FROM ubuntu:18.04
# Copying other directories in docker container
COPY . .
RUN apt-get update
# Installing development tools
RUN apt-get install -y git
RUN apt-get install -y curl
RUN apt install -y nano
RUN apt install -y tmux
# Installing Node
RUN curl -sL https://deb.nodesource.com/setup_16.x -o nodesource_setup.sh
RUN bash nodesource_setup.sh
RUN apt-get install -y nodejs
## Updating node to the supported version
RUN npm install -g npm@6
## Installing Python
RUN apt-get install python3 -y
## Installng dependencies
RUN npm install -g -y web3
RUN npm install -g -y ganache
RUN npm install -g -y truffle
# Installing node modules
RUN cd etheremum-simple-wallet-main/ethereum-wallet && npm install

Uploading the tarball

Overview of Docker container options on platformOverview of Docker container options on platform

Once you start uploading, the changes will only be visible once you save the course, so press SAVE.

Dockerfile is uploadingDockerfile is uploading

Dockerfile is uploading

Image is being builtImage is being built

Image has been builtImage has been built

Image has been built

Docker Job

Create a new docker job by selecting Docker Job Type Live and adding the other fields like this:

  • Job Name: Write the name of the Docker Job
  • Input File Name: Write any file name because that doesn't matter in thi setup
  • Run Script: Set Run Script to echo "ETH" because we won't use it
  • Application Port: Set application port to 4000 or any port other than 3000 where the fronted will be runing.
  • Force Relaunch on Run: Mark the checkbox
  • Start Scrip: This is where the real magic happens. Our start script will be:
Press + to interact
cp -r usercode/ethereum-wallet etheremum-simple-wallet-main/ethereum-wallet && cd etheremum-simple-wallet-main/ethereum-wallet
tmux new-session "ganache -h 0.0.0.0 -p 3000" \; split-window "npm start" \; select-layout even-vertical

In the start script, we first copy the code from the SPA widget to the code directory. Then, we move into that directory and start a tmux session with 2 windows. In first window, we run ganache (our blockchain node) and in the second window, we run our Ethereum wallet.

Appendix

File to download

The file attached below can be used to set the environment on Educative’s Platform.

ethereum.tar.gz