How to Get Docker Token


SOAJS uses Docker Swarm as one of the container technologies to deploy from source code or to deploy resources in containers.

Docker Swarm by default requires certificates to be provided in the headers of every call made to its API using socket communication.

The following page explains the steps and which tools are needed that allows you to replace providing certificates with unique authentication tokens when making calls to the docker API.

1- Concept

SOAJS provides a shell script that you can run on any machines using Mac OSX or Linux Ubuntu.

This script will generate an authentication token and deploy a proxy container in your docker swarm cloud and associate the token with it.

The container is configured to bind itself to port 443 which redirects traffic to the native docker port 2376. This approach enables SOAJS to invoke the Docker API using https on port 443 and supply a token in the headers instead of native certificates.

From there on, all communication to docker will be trapped by this container, the token gets validated, and if the request is authentic, the container redirects the call to the native docker API.

2- Download & Run Docker Script

The script is available in the SOAJS Installer, once you download the installer as an NPM package, you can then run the script via your terminal.

Download and Run docker script
# download the SOAJS installer
> npm install soajs.installer

# locate and run the script
> cd soajs.installer/scripts/pre
> ./

Once you run the script, the docker container will be created, the token will be generated and printed as part of the output so you can use it.

Sample Script Output
cleaning up old manager container
Error: No such container: manager-docker-api

Deploying new manager container...

manager container deployed

* Use the following Token to connect to your docker deployment:

3- Provide SOAJS Console With Docker Token

Copy the token from the output of the docker script and simply provided in the form when integrating the cloud provider where the docker swarm is running. You can also use the same approach if docker swarm is running on your local machine.

Head to Develop / Infra Cloud Providers, click on Connect New Infra Provider choose Docker Machine then fill the token in the form input.

Once you click submit, SOAJS Console will take your inputs and attempt to establish a communication link with the Docker Swarm by using the token you provided it with.

If the call is successful then the infra is accepted and you can use it to deploy source code and resources.

4- Get Docker Token at any later stage

At any later stage, in case you lost or forgot the token, you can simply inspect the container and retrieve the token again.

Retrieve Docker Swarm API Token
# find the container
> docker ps 

CONTAINER ID        IMAGE                 COMMAND                 CREATED             STATUS              PORTS                                          NAMES
88fc27c1e5ba        soajsorg/docker-api   "node . -T dockerapi"   8 minutes ago       Up 9 minutes>2376/tcp,>2377/tcp   manager-docker-api

# inspect the container and grab the token value
> docker inspect manager-docker-api

# sample output where you can locate the token
"Env": [