Run Cloud9 workspaces locally

A very quick setup guide

theUnknown
3 min readJun 15, 2019

--

Assuming that you followed the steps in this guide and downloaded the workspaces from Cloud9 dashboard to your local machine. Unzip .tar into some ~/c9/downloaded-files folder.

Run the command below in your terminal to start the container:

In the preceding command:

  • --privileged gives the container permission to do almost everything that the host operating system can do.
  • -e sets simple environment variables in the container, in this case the IP address and port.
  • --name is a name for the image, in this case, myc9ws.
  • --mount makes a directory available to the container. source is the path to the directory on the host operating system (for example, ~/c9/downloaded-files/ or <drive>:\Users\<user_name>\c9\downloaded-files\ for Windows), and target is the path in the container that you can use to refer to that same directory (for example, /home/ubuntu/workspace/).
  • -d means to run the container in the background.
  • -t means to run the container with a pseudo terminal.
  • -p connects ports in the container to ports on the host operating system. If port 5050 is already in use on your local computer, change it to a different port.
  • <base_image_id> is the base image ID to use, which you noted previously (for example cloud9/ws-default). Docker pulls the base image down to your local computer if it doesn't already exist there. Note that pulling down a base image for the first time might take several minutes.
➜  ~ docker psCONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                                                                                            NAMES8a6f8e8490b4        cloud9/ws-nodejs    "/bin/sh -c '/bin/ba…"   23 seconds ago      Up 22 seconds       0.0.0.0:5050->5050/tcp, 0.0.0.0:9090->8080/tcp, 0.0.0.0:9091->8081/tcp, 0.0.0.0:9092->8082/tcp   myc9ws2➜  ~ docker exec -it myc9ws /bin/bash

In the preceding command:

  • -it means to display an interactive terminal for running commands in the container.
  • myc9ws is the name of the running container (can be anything).
  • /bin/bash to get a bash shell in the container.

STEP 1: DOWNLOAD, INSTALL, AND RUN CLOUD9 CORE

In the interactive terminal, run the following commands, one at a time, to download, install, and then run Cloud9 Core inside of the container.

rm -rf /home/ubuntu/workspace/*
chown -R ubuntu:ubuntu /home/ubuntu
curl -sL https://deb.nodesource.com/setup_10.x | bash - && apt-get install nodejs -y
export USER=ubuntu
export C9_PROJECT=c9-offline
export C9_USER=ubuntu
export C9_HOSTNAME=$IP
export C9_PORT=$PORT
export IDE_OFFLINE=1
alias c9=/var/c9sdk/bin/c9 > /etc/profile.d/offline.sh
su ubuntu
cd /var
sudo mkdir c9sdk
sudo chown ubuntu:ubuntu c9sdk
git clone https://github.com/c9/core.git c9sdk
cd c9sdk
scripts/install-sdk.sh
sudo chown -R ubuntu:ubuntu /home/ubuntu/workspace/
sudo chown -R ubuntu:ubuntu /home/ubuntu/.c9/
sudo apt-get install -y ufw
sudo ufw allow 5050
sudo ufw allow 8080
sudo ufw allow 8081
sudo ufw allow 8082
node server.js -w /home/ubuntu/workspace/ -a : -l 0.0.0.0 -p 5050

stop the server (ctrl+C), and install mongodb:

:/var/c9sdk (master) $ sudo apt-get install -y mongodb-org

run the server:

:/var/c9sdk (master) $ node server.js -w /home/ubuntu/workspace/ -a : -l 0.0.0.0 -p 5050

this will run the Cloud9 IDE, which is accessible in the browser through localhost: 5050.

STEP 2: ACCESS YOUR APP IN THE BROWSER

Now in the IDE in the terminal you can access your workspace contents:

:~/workspace/home/workspace/myApp $ node app.js

This will run your app and it will be accessible in the browser through localhost: 9090.

Some Useful commands for reviving the connection to mongodb

mongod — bind_ip=$IP — nojournal
mongod — repair

Resources used for this post:

--

--

theUnknown

Everything is unknown until it’s known. Self-learner.