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

Configuration parameters
ParameterDescriptionrequired
nameName of the connectortrue:config/request
hostnameDocker server hostnametrue: config/request
portPort on which docker server is runningtrue: config/request
certificate-dierctory-pathPath to certificate directory which sever uses for authenticationtrue: config/request
docker-api-versionDocker Api versiontrue: config/request
docker-registry-urlDocker registry URLtrue: config/request
Example
{
  "certificate-directory-path": "/home/example/.docker/",
  "docker-api-version": "1.26",
  "docker-registry-url": "https://index.docker.io/v1/",
  "hostname": "192.168.2.195",
  "name": "docker",
  "port": "2376"
}

Actions

create

Create container of Docker associated with provided container-name and image-name.

Request parameters
ParameterDescriptionrequired
actionContains the name of the operation: createtrue
container-nameContains the name of the docker container: container-nametrue
image-nameContains the image from which docker container is created:image-nametrue
hostnameDocker server hostnametrue: config/request
portPort on which docker server is runningtrue: config/request
certificate-directory-pathPath to certificate directory which sever uses for authenticationtrue: config/request
docker-api-versionDocker Api versiontrue: config/request
docker-registry-urlDocker registry URLtrue: config/request
Response parameters
ParameterDescription
exit-code and idReturn Id of the created docker container with success (0) message if successfully created else return exit code -1 with error message
Example
response = @call.connector("docker_connector_name")
                .set("action","create")
                .set("hostname","192.168.2.195")
                .set("certificate-directory-path","/home/example/.docker/")
                .set("docker-api-version","1.26")
			    .set("docker-registry-url","https://index.docker.io/v1/")
				.set("port","2376")
                .set("container-name","test")
				.set("image-name","ubuntu:latest")
                .sync

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

#print the response
@log.info("response #{response}") #response contain the success code with the id of the container if successfully 					created else -1 if failed with error message 

start

start container of Docker associated with provided container-id.

Request parameters
ParameterDescriptionrequired
actionaction to perform: starttrue
container-idContains the id of the docker container which you want to starttrue
hostnameDocker server hostnametrue: config/request
portPort on which docker server is runningtrue: config/request
certificate-directory-pathPath to certificate directory which sever uses for authenticationtrue: config/request
docker-api-versionDocker Api versiontrue: config/request
docker-registry-urlDocker registry URLtrue: config/request
Response parameters
ParameterDescription
exit-code and status messagecontainer start successfully it return success(0) otherwise return failed(-1)
Example
response = @call.connector("docker")
                .set("action","start")
                .set("container-id","1555a57c363d4f6750f9")
                .set("hostname","192.168.2.195")
                .set("certificate-directory-path","/home/example/.docker/")
                .set("docker-api-version","1.26")
			    .set("docker-registry-url","https://index.docker.io/v1/")
				.set("port","2376")
                .sync

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

stop

stop container of Docker associated with provided container-id.

Request parameters
ParameterDescriptionrequired
actionaction to perform: stoptrue
container-idContains the id of the docker container which you want to stoptrue
hostnameDocker server hostnametrue: config/request
portPort on which docker server is runningtrue: config/request
certificate-directory-pathPath to certificate directory which sever uses for authenticationtrue: config/request
docker-api-versionDocker Api versiontrue: config/request
docker-registry-urlDocker registry URLtrue: config/request
Response parameters
ParameterDescription
exit-code and status messagecontainer stopped successfully it return success(0) otherwise return failed(-1)
Example
response = @call.connector("docker")
                .set("action","stop")
                .set("container-id","1555a57c363d4f6750f9")
                .set("hostname","192.168.2.195")
                .set("certificate-directory-path","/home/example/.docker/")
                .set("docker-api-version","1.26")
			    .set("docker-registry-url","https://index.docker.io/v1/")
				.set("port","2376")
                .sync

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

pause

Pause container of Docker associated with provided container-id.

Request parameters
ParameterDescriptionrequired
actionaction to perform: pausetrue
container-idContains the id of the docker container which you want to pausetrue
hostnameDocker server host-nametrue: config/request
portPort on which docker server is runningtrue: config/request
certificate-directory-pathPath to certificate directory which sever uses for authenticationtrue: config/request
docker-api-versionDocker Api versiontrue: config/request
docker-registry-urlDocker registry URLtrue: config/request
Response parameters
ParameterDescription
exit-code and status messagecontainer paused successfully it return success(0) otherwise return failed(-1)
Example
response = @call.connector("docker")
                .set("action","pause")
                .set("container-id","1555a57c363d4f6750f9")
                .set("hostname","192.168.2.195")
                .set("certificate-directory-path","/home/example/.docker/")
                .set("docker-api-version","1.26")
			    .set("docker-registry-url","https://index.docker.io/v1/")
				.set("port","2376")
                .sync

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

unpause

Unpause container of Docker associated with provided container-id.

Request parameters
ParameterDescriptionrequired
actionaction to perform: unpausetrue
container-idContains the id of the docker container which you want to unpausetrue
hostnameDocker server host-nametrue: config/request
portPort on which docker server is runningtrue: config/request
certificate-directory-pathPath to certificate directory which sever uses for authenticationtrue: config/request
docker-api-versionDocker Api versiontrue: config/request
docker-registry-urlDocker registry URLtrue: config/request
Response parameters
ParameterDescription
exit-code and status messagecontainer unpaused successfully it return success(0) otherwise return failed(-1)
Example
response = @call.connector("docker")
                .set("action","unpause")
                .set("container-id","1555a57c363d4f6750f9")
                .set("hostname","192.168.2.195")
                .set("certificate-directory-path","/home/example/.docker/")
                .set("docker-api-version","1.26")
			    .set("docker-registry-url","https://index.docker.io/v1/")
				.set("port","2376")
                .sync

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

restart

Restart container of Docker associated with provided container-id.

Request parameters
ParameterDescriptionrequired
actionaction to perform: restarttrue
container-idContains the id of the docker container which you want to restarttrue
hostnameDocker server host-nametrue: config/request
portPort on which docker server is runningtrue: config/request
certificate-directory-pathPath to certificate directory which sever uses for authenticationtrue: config/request
docker-api-versionDocker Api versiontrue: config/request
docker-registry-urlDocker registry URLtrue: config/request
Response parameters
ParameterDescription
exit-code and status messagecontainer restarted successfully it return success(0) otherwise return failed(-1)
Example
response = @call.connector("docker")
                .set("action","restart")
                .set("container-id","1555a57c363d4f6750f9")
                .set("hostname","192.168.2.195")
                .set("certificate-directory-path","/home/example/.docker/")
                .set("docker-api-version","1.26")
			    .set("docker-registry-url","https://index.docker.io/v1/")
				.set("port","2376")
                .sync

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

remove

Remove container from Docker registry associated with provided container-id.

Request parameters
ParameterDescriptionrequired
actionaction to perform: removetrue
container-idContains the id of the docker container which you want to removetrue
hostnameDocker server host-nametrue: config/request
portPort on which docker server is runningtrue: config/request
certificate-directory-pathPath to certificate directory which sever uses for authenticationtrue: config/request
docker-api-versionDocker Api versiontrue: config/request
docker-registry-urlDocker registry URLtrue: config/request
Response parameters
ParameterDescription
successcontainer removed successfully it return true(0) otherwise false(-1) with error message
Example
response = @call.connector("docker")
                .set("action","remove")
                .set("container-id","1555a57c363d4f6750f9")
                .set("hostname","192.168.2.195")
                .set("certificate-directory-path","/home/example/.docker/")
                .set("docker-api-version","1.26")
			    .set("docker-registry-url","https://index.docker.io/v1/")
				.set("port","2376")
                .sync

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

pull-image

pull image of Docker associated with provided image-name.

Request parameters
ParameterDescriptionrequired
actionaction to perform: pull-imagetrue
image-nameContains the image with tag which you want to pull docker hub registrytrue
hostnameDocker server host-nametrue: config/request
portPort on which docker server is runningtrue: config/request
certificate-directory-pathPath to certificate directory which sever uses for authenticationtrue: config/request
docker-api-versionDocker Api versiontrue: config/request
docker-registry-urlDocker registry URLtrue: config/request
Response parameters
ParameterDescription
ext-code and status codecontainer pulled successfully it return true(0) otherwise false(-1) with error message
Example
response = @call.connector("docker")
                .set("action","pull-image")
                .set("image-name","ubuntu:latest")
                .set("hostname","192.168.2.195")
                .set("certificate-directory-path","/home/example/.docker/")
                .set("docker-api-version","1.26")
			    .set("docker-registry-url","https://index.docker.io/v1/")
				.set("port","2376")
                .sync

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

list-containers

list containers present in docker registry.

Request parameters
ParameterDescriptionrequired
actionaction to perform: list-containerstrue
hostnameDocker server host-nametrue: config/request
portPort on which docker server is runningtrue: config/request
certificate-directory-pathPath to certificate directory which sever uses for authenticationtrue: config/request
docker-api-versionDocker Api versiontrue: config/request
docker-registry-urlDocker registry URLtrue: config/request
Response parameters
ParameterDescription
container-listif successfully executed return list of connector with exit code 0 otherwise return false(-1) with error message
Example
response = @call.connector("docker_connector_name")
                .set("action","list-containers")
                .set("hostname","192.168.2.195")
                .set("certificate-directory-path","/home/example/.docker/")
                .set("docker-api-version","1.26")
			    .set("docker-registry-url","https://index.docker.io/v1/")
				.set("port","2376")
                .sync

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

list-process

list processes running for given container with provided container-id.

Request parameters
ParameterDescriptionrequired
actionaction to perform: list-processtrue
container-idContains the id for which you want to list processestrue
hostnameDocker server host-nametrue: config/request
portPort on which docker server is runningtrue: config/request
certificate-directory-pathPath to certificate directory which sever uses for authenticationtrue: config/request
docker-api-versionDocker Api versiontrue: config/request
docker-registry-urlDocker registry URLtrue: config/request
Response parameters
ParameterDescription
process-listlist of process if executed successfully with exit code 0 otherwise return -1 with error message
Example
response = @call.connector("docker")
                .set("action","list-process")
                .set("conatainer-id","1555a57c363d4f6750f9")
                .set("hostname","192.168.2.195")
                .set("certificate-directory-path","/home/example/.docker/")
                .set("docker-api-version","1.26")
			    .set("docker-registry-url","https://index.docker.io/v1/")
				.set("port","2376")
                .sync

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

list-images

list images associated with given docker registry.

Request parameters
ParameterDescriptionrequired
actionaction to perform: list-imagestrue
hostnameDocker server host-nametrue: config/request
portPort on which docker server is runningtrue: config/request
certificate-directory-pathPath to certificate directory which sever uses for authenticationtrue: config/request
docker-api-versionDocker Api versiontrue: config/request
docker-registry-urlDocker registry URLtrue: config/request
Response parameters
ParameterDescription
image-listlist of images if executed successfully with exit code 0 otherwise return -1 with error message
Example
response = @call.connector("docker")
                .set("action","list-images")
                .set("hostname","192.168.2.195")
                .set("certificate-directory-path","/home/example/.docker/")
                .set("docker-api-version","1.26")
			    .set("docker-registry-url","https://index.docker.io/v1/")
				.set("port","2376")
                .sync

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

inspect-container

inspect container associated with provided container-id.

Request parameters
ParameterDescriptionrequired
actionaction to perform: inspect-containertrue
container-idContains the id of container which you want to inspecttrue
hostnameDocker server host-nametrue: config/request
portPort on which docker server is runningtrue: config/request
certificate-directory-pathPath to certificate directory which sever uses for authenticationtrue: config/request
docker-api-versionDocker Api versiontrue: config/request
docker-registry-urlDocker registry URLtrue: config/request
Response parameters
ParameterDescription
container-detailsdetails of container if executed successfully with exit code 0 otherwise return -1 with error message
Example
response = @call.connector("docker")
                .set("action","inspect-container")
                .set("container-id","1555a57c363d4f6750f9")
                .set("hostname","192.168.2.195")
                .set("certificate-directory-path","/home/example/.docker/")
                .set("docker-api-version","1.26")
			    .set("docker-registry-url","https://index.docker.io/v1/")
				.set("port","2376")
                .sync

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

rename-container

pull image of Docker associated with provided container-id.

Request parameters
ParameterDescriptionrequired
actionaction to perform: rename-containertrue
container-idContains the id of container which you want to renametrue
container-nameNew container name which you want to give to containertrue
hostnameDocker server host-nametrue: config/request
portPort on which docker server is runningtrue: config/request
certificate-directory-pathPath to certificate directory which sever uses for authenticationtrue: config/request
docker-api-versionDocker Api versiontrue: config/request
docker-registry-urlDocker registry URLtrue: config/request
Response parameters
ParameterDescription
exit-code and status codecontainer renamed successfully it return true(0) otherwise false(-1) with error message
Example
response = @call.connector("docker_connector_name")
                .set("action","rename-container")
                .set("container-id","242342356778f")
                .set("container-name","test")
                .set("hostname","192.168.2.195")
                .set("certificate-directory-path","/home/example/.docker/")
                .set("docker-api-version","1.26")
			    .set("docker-registry-url","https://index.docker.io/v1/")
				.set("port","2376")
                .sync

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

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: