Docker Setup
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
-tarball--Dockerfile--[OTHER FILES]
The above shows the directory structure of our tarball.
The command to create this tarball is as follows:
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
FROM ubuntu:18.04# Copying other directories in docker containerCOPY . .RUN apt-get update# Installing development toolsRUN apt-get install -y gitRUN apt-get install -y curlRUN apt install -y nanoRUN apt install -y tmux# Installing NodeRUN curl -sL https://deb.nodesource.com/setup_16.x -o nodesource_setup.shRUN bash nodesource_setup.shRUN apt-get install -y nodejs## Updating node to the supported versionRUN npm install -g npm@6## Installing PythonRUN apt-get install python3 -y## Installng dependenciesRUN npm install -g -y web3RUN npm install -g -y ganacheRUN npm install -g -y truffle# Installing node modulesRUN cd etheremum-simple-wallet-main/ethereum-wallet && npm install
Uploading the tarball
Once you start uploading, the changes will only be visible once you save the course, so press SAVE
.
Dockerfile is uploading
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 than3000
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:
cp -r usercode/ethereum-wallet etheremum-simple-wallet-main/ethereum-wallet && cd etheremum-simple-wallet-main/ethereum-wallettmux 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.