A docker container that can build, install and run Apache Knox from a configured git repository and branch.
By default, branch v.2.2.0 is built and installed, variables knoxurl and branch defined in docker-compose.yml file can be used to choose a different repository and branch to build. A demo ldap server is also started, used by Apache Knox for authentication.
This is useful for testing Apache Knox topologies and for developing service definitions used for introducing UI and REST API proxying capabilities.
Starting Knox dev container:
docker-compose up -d- If you need to build using a specific repo and branch you can add the following environment variables to your shell environment (i.e.
export knoxurl=https://github.com/apache/knox.git).knoxurlbranch
To access Admin UI:
Instructions for Knox Zeppelin demo:
docker-compose -f docker-compose-zeppelin.yml up -d- Go to
https://localhost:8443/gateway/sandbox/zeppelin/
- docker-compose version 3 required.
- To understand UI Proxying with Knox please refer to this excellent guide - Proxying UI using Knox
- For more information and explanation on Knox please refer to the Dev guide
- By default branch v.1.1.0 is used.
Build a Knox dev container using docker-compose. we can use this as a base image to build on.
- Checkout this repository
git clone https://github.com/moresandeep/knox-dev-docker.git cd knox-dev-docker- Check your docker compose file i.e. either
docker-compose.ymlordocker-compose-zeppelin.ymland update thebranchvariable to the branch you want to build. docker-compose up -dThis builds the Knox dev container if not already present by checking out code from the provided git repo (in docker-compose.yml). Starts a docker container with- Test ldap container and
- Knox gateway container
docker psshould show your gateway and ldap containers running.- run
docker-compose stopto stop the containers. - To stops containers and removes containers, networks, volumes, and images run
docker-compose down.
This section talks about common configuration settings used by Knox dev container and how they can be changed.
- Knox gateway listening on port 8443, to change it, modify the
ports:setting indocker-compose.yml, note the format isHOST-PORT:CONTAINER-PORT. - Following is the folder mapping:
./topologiesfolder will be mapped to/knox/knox-0.10.0-SNAPSHOT/conf/topologiesfolder in the container./zeppelinuifolder will be mapped to/knox/knox-0.10.0-SNAPSHOT/data/services/zeppelinuifolder in the container./zeppelinwsfolder will be mapped to/knox/knox-0.10.0-SNAPSHOT/data/services/zeppelinwsfolder in the container.
- To add and remove mappings use the
volumes:settings indocker-compose.yml. - Change the git command in
docker-compose.ymlto build from a specific release.
Here we describe how a new service can be added. We will need the containers to be stopped in order for the new service to be added this is because we will be adding new mappings to our existing containers (e.g. volumes and/or ports).
-
Please refer to Proxying UI using Knox to understand the basic concepts, especially how to add services (rewrite.xml, service.xml) and how to update the topology file.
-
We will try to add a new service to Knox, let's take an example of adding a Weather service as described here - Adding a service to Apache Knox. Make sure you get the App Id from http://openweathermap.org (if using this example).
-
Under the
knox-dev-dockerfolder (where this repository is checked out) add the service definition files needed by your service e.g.weather/0.0.1/service.xml- The service.xml file defines the high level URL patterns that will be exposed by the gateway for a service.weather/0.0.1/rewrite.xml- The rewrite.xml is configuration that drives the rewrite provider within Knox.
-
Now go to
topologies/sandbox.xmlfile on your machine and add the following service definition `
- To add a new service, simply add a service.xml and rewrite.xml file in an appropriate directory (
/knox/gateway-service-definitions/src/main/resources) in the modulegateway-service-definitionsto make the new service part of the Knox build. - See https://knox.apache.org/books/knox-0-9-1/dev-guide.html#Service+Definition+Directory+Structure for Knox Service Definition Directory Structure.
An example of Knox proxying Zeppelin UI and websocket connections. This example is already configured and runs out of the box.
This example demos how Knox can proxy Zeppelin UI and proxy underlying Websocket connections using the necessary service files and service definitions.
You can change the git command in docker-compose-zeppelin.yml to build from a specific release if you choose.
Also refer to the docker-compose-zeppelin.yml file for more settings if you want more control on the docker instances.
Instructions to run Knox Zeppelin demo:
docker-compose -f docker-compose-zeppelin.yml up -d- Go to
https://localhost:8443/gateway/sandbox/zeppelin/
- In case you get error such as
cannot stat /knox/knox-0.11.0-SNAPSHOTwhile building the knox-dev image go to your docker compose file i.e. eitherdocker-compose.ymlordocker-compose-zeppelin.ymland update theknoxversionproperty to the current version that Knox master is using. Please let me know or submit a PR if possible.