...

/

Docker Setup

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 as 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
--app.py
--server.js

The above shows the directory structure of our tarball.

The command to create this tarball is as follows:

tar -czvf GQLS.tar.gz Dockerfile app.py server.js

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.

The other two files i.e app.py and server.js.

app.py and server.js just has code for testing and is also optional, it is already provided in the lessons that follow.

Points to Note:

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

Dockerfile

Press + to interact
FROM ubuntu:20.04
RUN apt-get update &&\
apt-get install -y python3 &&\
apt-get install -y python3-pip &&\
pip install numpy &&\
pip install pandas &&\
pip install graphene &&\
pip install strawberry-graphql &&\
pip install 'strawberry-graphql[debug-server]' &&\
pip install tartiflette &&\
pip install qlient
RUN apt-get update &&\
apt install -y curl git &&\
curl -sL https://deb.nodesource.com/setup_14.x -o nodesource_setup.sh &&\
bash nodesource_setup.sh &&\
apt install -y nodejs &&\
npm install -y express express-graphql graphql
COPY . .

Line 1: FROM ubuntu:20.04 :

The FROM command sets the Base Image for the rest of the instructions. This command must be on top of the Dockerfile.

In this example, we are starting with the base image of ubuntu:20.04. This will allow us to install Python and NodeJS side by side. Make sure you use ubuntu:20.04 version in your Dockerfile if you are making a LiveVM

You can use a specific version of your base image, by appending : and the version_name at the end of the image name. In case of LiveVM setup, whatever base image you use, you need to install ubuntu:20.04 via Dockerfile for the SPA + LiveVM to work.

For code widget this is not necessary.

Lines 2-11:

RUN apt-get update &&\
    apt-get install -y python3 &&\
    apt-get install -y python3-pip &&\
    pip install numpy &&\
    pip install pandas &&\
    pip install graphene &&\
    pip install strawberry-graphql &&\
    pip install 'strawberry-graphql[debug-server]' &&\
    pip install tartiflette &&\
    pip install qlient

The RUN command is used to execute instructions against the image. It is used to run a command during the build process of the docker image.

Other commands are updating and downloading the required Python packages for GraphQL.

Lines 13-18:

RUN apt-get update &&\
	apt install -y curl git &&\
	curl -sL https://deb.nodesource.com/setup_14.x -o nodesource_setup.sh &&\
	bash nodesource_setup.sh &&\
	apt install -y nodejs &&\
    npm install -y express express-graphql graphql

These lines will install NodeJS and other required packages for GraphQL.

Line 20:

COPY . .

This line will copy all tarball files in our created image.

In our case app.py and server.js will get copied in it.

Uploading the Tarball

Appendix

File to download

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

GQLS.tar.gz

Access this course and 1200+ top-rated courses and projects.