Skip to content

Build and run GraphSpace Comment system using DockerFile

Subramanyam Makam edited this page Apr 2, 2019 · 7 revisions

Running Docker

The reason we have a docker setup is to make it easier for you to run GraphSpace on your local machine. Follow these steps to build and run the graphspace docker image on your machine to setup the comment system locally:

  1. Install Docker

    Check out How To Install and Use Docker on Ubuntu 16.04 to learn how to install Docker on Ubuntu instances.

  2. Install Docker-compose

    Check out How To Install Docker Compose on Ubuntu 16.04 to learn how to install Docker Compose on Ubuntu instances.

  3. Clone the GraphSpace repo

    git clone -b comment-system https://github.com/bruce-wayne99/GraphSpace.git

  4. Go to GraphSpace repo.

  5. Purging all dangling and unused images, containers, volumes, and networks

    # These commands work for Ubuntu 16.04
    sudo docker system prune
    sudo docker system prune -a
    
  6. Run docker

    sudo docker-compose up
    
  7. Go to 0.0.0.0:8002 in your browser to access GraphSpace.

Questions that documentation needs to address

  1. How did you create this docker build?
  • I have created this docker build with the help of Dockerfile. A Dockerfile is a text file that has a series of instructions on how to build your image. It supports a simple set of commands that we can use in our Dockerfile.
  • On a whole, a Dockerfile helps in building an image with packages installed inside it, here I have used the Dockerfile to install all the necessary dependencies and packages to run GraphSpace.
  • For packages such as redis, elasticsearch we have to configure them first before using. So, we keep a set of configuration files and copy them to the necessary locations for updating the configuration once the image is built successfully.
  • I have included a script which runs once the image has been built successfully which copies the necessary configuration files, creates database and starts the GraphSpace server.
  • Finally we have to forward the port to our local machine on which the docker container is running so that we can use the application in our browser on localhost.
  • I have used Docker Compose to integrate the process of building the image, configuring the installed packages, running the GraphSpace server and forwarding the port.
  1. What are the required code changes to use this docker? Explain the purpose of each file added to the code base.
  • Some of the files added/modified while setting up GraphSpace using docker are as follows:
    1. docker.py: The Django server is ran using this settings file inside the docker container. Since we have to create a database with credentials, this file is a copy of normal Django settings file with edited database credentials.
    2. redis.conf: This file is necessary for loading the Redis configuration (port number, hostname to run on etc)
    3. elasticsearch.yml: Similar to redis this file is necessary for loading the Elasticsearch configuration (cluster and node name etc).
    4. docker_command.sh: This script runs while the image is build which copies the configuration files and starts the Django server.
    5. Dockerfile: This file is used to build the graphspace docker image which is build on an ubuntu:16.04 base image. It contains a list of commands for installing all the dependencies for GraphSpace.
    6. docker-compose.yml: Helps in integrating the whole process of building the docker image, running the docker_command.sh script and forwarding the port.
  1. How can a Django app running in a docker instance interface with Apache?
  • This can be done in a similar way in which we tried to install and configure redis and elasticsearch. Based on the instructions for setting up GraphSpace on Apache, the below instructions would be sufficient to setup GraphSpace on Apache.
    1. First we have to add instructions to install Apache2 and libapache2-mod-wsgi in Dockerfile.
    2. Next we create a configuration file for Apache2 and add instructions to copy to the apache2 configuration directory.
    3. We add necessary instructions indicated here to redirect HTTP requests to requests to Apache and web socket requests to Daphne.
    4. Restart the apache2 server and start daphne server.
  1. How can a developer run this docker build on their local machines and test their code changes? Explain the process.
  • The developer can achieve this facility with the help of docker volumes. We can mount the directory of GraphSpace in our machine on docker container. Say we want to run a container for an image graphspace:latest, then we can start a container using the below command:

      `docker run -d -p 80:8002 -v "/Path_to_GraphSpace_on_your_machine/":/GraphSpace graphspace:latest`
    
    1. This command ensures to reflect the code changes in GraphSpace directory on your machine to the GraphSpace directory on docker.
    2. After making code changes, we can refresh the browser page and directly see the changes.

Clone this wiki locally