Docker Setup
We'll cover the following...
Docker on the Educative Platform
We use Docker to allow authors to create their custom environments to accommodate any language not supported by our platform.
Authors can create custom docker images that deploy on the Google Cloud and allow end-users to have access to these customized environments through our platform directly.
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 our application environment, basically where our application will be run.
-tarball--Dockerfile---project1 // Folder containing the all the files of project1---src----server.js----package.json
Use the command line terminal to navigate to the directory where your Dockerfile is
Move all the project files the course needs into the main directory where your Dockerfile is.
If we need to add multiple projects, we can create a separate directory for each one and add all the necessary files.
In the terminal, use the following command to turn these assets into a tarball:
tar -czvf apollo.tar.gz Dockerfile project1
This command will take the Dockerfile
and project1
directory as inputs and create a single tarball file as output. The tarball file will be named apollo.tar.gz
.
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.
Now, we’ll dive into the contents of our Dockerfile
.
Dockerfile
Note: We have to perform this step locally (on our computer).
Create a Dockerfile by adding the following script to an empty text file saved as
Dockerfile
(with no extension):
# Base container image, which has Nodejs pre-installedFROM node:14# Copy project filesCOPY . .# Navigating to the project directory and install all the packages.RUN cd project1/src && npm install -g nodemon && npm install
Explanation
Docker uses the instructions in your Dockerfile to build a Docker image. This image will be used to run GraphQL using Apollo Studio. Let’s take a look at what our Dockerfile contains.
Line 2: We are using the
node:14
as the base image of our Dockerfile.Line 4: We are copying all the files attached in
.tar.gz
file to the container, which includes all the files in theproject1
directory.Line 6: We are navigating to
project1/src
and installing all the required node packages to run the project.