Docker Connector

Docker containers wrap up a piece of software in a complete filesystem that contains everything it needs to run: code, runtime, system tools, system libraries – anything you can install on a server. This guarantees that it will always run the same, regardless of the environment it is running in..

With this document guide you will be able to work with and use a Docker Connector. While you start configuring the connector, this document will guide you through Docker Connector request and response parameters.

Design Aspects

Perform all standard application operations like Create, Start and Stop operations available through the Docker rest api. Some of them are listed below:

  • Create Container
  • Inspect Container
  • List Container
  • Pause Container
  • Unpause instance
  • Start Container
  • Stop Container
  • Restart Container
  • Remove Container
  • List Images
  • Process
  • Rename Container
  • Pull Images Also,

  • The ability to set Connector execution timeouts
  • Synchronous / Asynchronous execution of the Connector

Configuring DigitalOcean Connector

docker

Configuration parameters
ParameterDescriptionrequired
public-keyDocker client public-key Credentialstrue: config/request
certificateDocker client certificate Credentialstrue: config/request
private-keyDocker client private-key Credentialstrue: config/request
hostnameDocker client hostname Credentialstrue: config/request
port-keyDocker client port Credentialstrue: config/request
Example
{
  "public-key" : "/home/user/client_files/ca.pem",
  "certificate" : "/home/user/client_files/cert.pem",
  "private-key" : "/home/user/client_files/key.pem",
  "hostname" : "localhost",
  "port-key" : 2376 
}

Actions

create

Create container of Docker associated with provided name.

Request parameters
ParameterDescriptionrequired
actionContains the name of the operation: createtrue
nameContains the name of the docker container: nametrue
imageContains the image from which docker container is created: imagetrue
public-keySpecifies the credentials for authenticate the Docker servertrue: config/request
private-keySpecifies the credentials for authenticate the Docker servertrue: config/request
certificationSpecifies the credentials for authenticate the Docker servertrue: config/request
portPort to connect to on the Docker server.true: config/request
hostnamehostname or IP address to connect to on the Docker server.true: config/request
Response parameters
ParameterDescriptionrequired
WarningsWarnings while creating docker containertrue
IdId of the created docker containertrue
Example
response = @call.connector("docker_connector_name")
                .set("action","create")
                .set("image","ubuntu:latest")
                .set("public-key","/home/user/clientFiles/ca.pem")
                .set("certificate","/home/user/clientFiles/cert.pem")
                .set("private-key","/home/user/clientFiles/key.pem")
                .set("hostname","localhost")
                .set("port",2376)
                .set("name","container-name")
                .sync

#Docker Connector Response Meta Parameters
response_exitcode = response.exitcode               #Exit status code
response_message = response.message                 #Execution status messages

#Docker Connector Response Parameters
warnings=response.get("Warnings")                   #Warnings while creating docker container
Id=response.get("Id")                               #Id of the created docker container

start

start container of Docker associated with provided name.

Request parameters
ParameterDescriptionrequired
actionaction to perform: starttrue
idContains the id of the docker container which you want to starttrue
public-keySpecifies the credentials for authenticate the Docker servertrue: config/request
private-keySpecifies the credentials for authenticate the Docker servertrue: config/request
certificationSpecifies the credentials for authenticate the Docker servertrue: config/request
portPort to connect to on the Docker server.true: config/request
hostnamehostname or IP address to connect to on the Docker server.true: config/request
Response parameters
ParameterDescriptionrequired
response-coderesponse code of the request to docker servertrue
successcontainer start successfully it return true otherwise falsetrue
Example
response = @call.connector("docker_connector_name")
                .set("action","start")
                .set("id","1555a57c363d4f6750f9")
                .set("public-key","/home/user/clientFiles/ca.pem")
                .set("certificate","/home/user/clientFiles/cert.pem")
                .set("private-key","/home/user/clientFiles/key.pem")
                .set("hostname","localhost")
                .set("port",2376)
                .sync

#Docker Connector Response Meta Parameters
response_exitcode = response.exitcode                #Exit status code
response_message = response.message                  #Execution status messages

#Docker Connector Response Parameters
response_code=response.get("response-code")          #Response code
response_status=response.get("success")              #Response status
 

stop

stop container of Docker associated with provided name.

Request parameters
ParameterDescriptionrequired
actionaction to perform: stoptrue
idContains the id of the docker container which you want to stoptrue
public-keySpecifies the credentials for authenticate the Docker servertrue: config/request
private-keySpecifies the credentials for authenticate the Docker servertrue: config/request
certificationSpecifies the credentials for authenticate the Docker servertrue: config/request
portPort to connect to on the Docker server.true: config/request
hostnamehostname or IP address to connect to on the Docker server.true: config/request
Response parameters
ParameterDescriptionrequired
response-coderesponse code of the request to docker servertrue
successcontainer stopped successfully it return true otherwise falsetrue
Example
response = @call.connector("docker_connector_name")
                .set("action","stop")
                .set("id","1555a57c363d4f6750f9")
                .set("public-key","/home/user/clientFiles/ca.pem")
                .set("certificate","/home/user/clientFiles/cert.pem")
                .set("private-key","/home/user/clientFiles/key.pem")
                .set("hostname","localhost")
                .set("port",2376)
                .sync

#Docker Connector Response Meta Parameters
response_exitcode = response.exitcode                #Exit status code
response_message = response.message                  #Execution status messages

#Docker Connector Response Parameters
response_code=response.get("response-code")          #Response code
response_status=response.get("success")              #Response status 
 

pause

Pause container of Docker associated with provided name.

Request parameters
ParameterDescriptionrequired
actionaction to perform: pausetrue
idContains the id of the docker container which you want to pausetrue
public-keySpecifies the credentials for authenticate the Docker servertrue: config/request
private-keySpecifies the credentials for authenticate the Docker servertrue: config/request
certificationSpecifies the credentials for authenticate the Docker servertrue: config/request
portPort to connect to on the Docker server.true: config/request
hostnamehostname or IP address to connect to on the Docker server.true: config/request
Response parameters
ParameterDescriptionrequired
response-coderesponse code of the request to docker servertrue
successcontainer paused successfully it return true otherwise falsetrue
Example
response = @call.connector("docker_connector_name")
                .set("action","pause")
                .set("id","1555a57c363d4f6750f9")
                .set("public-key","/home/user/clientFiles/ca.pem")
                .set("certificate","/home/user/clientFiles/cert.pem")
                .set("private-key","/home/user/clientFiles/key.pem")
                .set("hostname","localhost")
                .set("port",2376)
                .sync

#Docker Connector Response Meta Parameters
response_exitcode = response.exitcode                #Exit status code
response_message = response.message                  #Execution status messages

#Docker Connector Response Parameters
response_code=response.get("response-code")          #Response code
response_status=response.get("success")              #Response status 

unpause

Unpause container of Docker associated with provided name.

Request parameters
ParameterDescriptionrequired
actionaction to perform: unpausetrue
idContains the id of the docker container which you want to unpausetrue
public-keySpecifies the credentials for authenticate the Docker servertrue: config/request
private-keySpecifies the credentials for authenticate the Docker servertrue: config/request
certificationSpecifies the credentials for authenticate the Docker servertrue: config/request
portPort to connect to on the Docker server.true: config/request
hostnamehostname or IP address to connect to on the Docker server.true: config/request
Response parameters
ParameterDescriptionrequired
response-coderesponse code of the request to docker servertrue
successcontainer unpaused successfully it return true otherwise falsetrue
Example
response = @call.connector("docker_connector_name")
                .set("action","unpause")
                .set("id","1555a57c363d4f6750f9")
                .set("public-key","/home/user/clientFiles/ca.pem")
                .set("certificate","/home/user/clientFiles/cert.pem")
                .set("private-key","/home/user/clientFiles/key.pem")
                .set("hostname","localhost")
                .set("port",2376)
                .sync

#Docker Connector Response Meta Parameters
response_exitcode = response.exitcode                #Exit status code
response_message = response.message                  #Execution status messages

#Docker Connector Response Parameters
response_code=response.get("response-code")          #Response code
response_status=response.get("success")              #Response status 

restart

Restart container of Docker associated with provided name.

Request parameters
ParameterDescriptionrequired
actionaction to perform: restarttrue
idContains the id of the docker container which you want to restarttrue
public-keySpecifies the credentials for authenticate the Docker servertrue: config/request
private-keySpecifies the credentials for authenticate the Docker servertrue: config/request
certificationSpecifies the credentials for authenticate the Docker servertrue: config/request
portPort to connect to on the Docker server.true: config/request
hostnamehostname or IP address to connect to on the Docker server.true: config/request
Response parameters
ParameterDescriptionrequired
response-coderesponse code of the request to docker servertrue
successcontainer restart successfully it return true otherwise falsetrue
Example
response = @call.connector("docker_connector_name")
                .set("action","restart")
                .set("id","1555a57c363d4f6750f9")
                .set("public-key","/home/user/clientFiles/ca.pem")
                .set("certificate","/home/user/clientFiles/cert.pem")
                .set("private-key","/home/user/clientFiles/key.pem")
                .set("hostname","localhost")
                .set("port",2376)
                .sync

#Docker Connector Response Meta Parameters
response_exitcode = response.exitcode                #Exit status code
response_message = response.message                  #Execution status messages

#Docker Connector Response Parameters
response_code=response.get("response-code")          #Response code
response_status=response.get("success")              #Response status 

remove

Remove container of Docker associated with provided name.

Request parameters
ParameterDescriptionrequired
actionaction to perform: removetrue
idContains the id of the docker container which you want to removetrue
public-keySpecifies the credentials for authenticate the Docker servertrue: config/request
private-keySpecifies the credentials for authenticate the Docker servertrue: config/request
certificationSpecifies the credentials for authenticate the Docker servertrue: config/request
portPort to connect to on the Docker server.true: config/request
hostnamehostname or IP address to connect to on the Docker server.true: config/request
Response parameters
ParameterDescriptionrequired
response-coderesponse code of the request to docker servertrue
successcontainer removed successfully it return true otherwise falsetrue
Example
response = @call.connector("docker_connector_name")
                .set("action","remove")
                .set("id","1555a57c363d4f6750f9")
                .set("public-key","/home/user/clientFiles/ca.pem")
                .set("certificate","/home/user/clientFiles/cert.pem")
                .set("private-key","/home/user/clientFiles/key.pem")
                .set("hostname","localhost")
                .set("port",2376)
                .sync

#Docker Connector Response Meta Parameters
response_exitcode = response.exitcode                #Exit status code
response_message = response.message                  #Execution status messages

#Docker Connector Response Parameters
response_code=response.get("response-code")          #Response code
response_status=response.get("success")              #Response status 

pull

pull image of Docker associated with provided name.

Request parameters
ParameterDescriptionrequired
actionaction to perform: pulltrue
imageContains the image with tag which you want to pull docker hub registrytrue
public-keySpecifies the credentials for authenticate the Docker servertrue: config/request
private-keySpecifies the credentials for authenticate the Docker servertrue: config/request
certificationSpecifies the credentials for authenticate the Docker servertrue: config/request
portPort to connect to on the Docker server.true: config/request
hostnamehostname or IP address to connect to on the Docker server.true: config/request
Response parameters
ParameterDescriptionrequired
resultPulled image resulttrue
Example
response = @call.connector("docker_connector_name")
                .set("action","remove")
                .set("image","ubuntu:latest")
                .set("public-key","/home/user/clientFiles/ca.pem")
                .set("certificate","/home/user/clientFiles/cert.pem")
                .set("private-key","/home/user/clientFiles/key.pem")
                .set("hostname","localhost")
                .set("port",2376)
                .sync

#Docker Connector Response Meta Parameters
response_exitcode = response.exitcode               #Exit status code
response_message = response.message                 #Execution status messages

#Docker Connector Response Parameters
response_code=response.get("result")                #Pulled image result 
 

Connector request error handling

Here is how you can handle the connector requests success or failures within your Flintbit. This would help you to take appropriate action if something failed. 

if response.exitcode == 0                      # 0 is success.
  @log.info("success")
  # take action in case of success
else                                           # non zero means fail
  @log.error("fail")
  @log.error("Reason:" + response.message)     # get the reason of failure
  ## Take action in case of failure
end

 

 

On this page: