Get the host URL from inside Janitor



I’m trying to write code for auto-configuring preview URLs in Cloud9. Generating these URLs requires me to know the correct host name, port numbers, and container name (to get something like https://[host_name]/?container=[container_id]&port=[port_num]).

The port number is in the config file itself, and the container ID is in /proc/self/cgroup.

Where’s the host name?


Would it help if, right after a container is spawned, we quickly copy over some configuration file including the hostname and container ID?

Or maybe there is a way to start a container with a few additional environment variables.


The hostname should also be in window.location, if you have access to that.


Well, the docker create command, and the create container API, both allow you to specify env variables at the time you create the container. That won’t work for fetching the container ID, since that’s generated after the container is created, but it’s fine for the host name.


So either we extract the hostname from window.location in the Cloud9 plugin code, or if that doesn’t work, we can add an environment variables parameter to docker.runContainer which is called here when spawning a new container.



Thanks again for implementing the “Preview” button configuration for all Janitor containers! This is a huge improvement that will make many people happy.

As a side-note, the change wasn’t yet included in our Docker images, because we re-use cached instructions when building ubuntu-dev (and the RUN command which does the git clone c9.ide.janitor.config didn’t change, so a cached result was re-used).

In this pull request, I made some upgrades to some RUN commands above the Cloud9 SDK set up, hence invalidating the cache, but the new build didn’t actually succeed because of a problem with rls (it’s not available in the latest Rust Nightly, breaking our Docker image build, see this rls issue).