Docker
Since Camel 2.15
Both producer and consumer are supported
Camel component for communicating with Docker.
The Docker Camel component leverages the docker-java via the Docker Remote API.
URI format
docker://[operation]?[options]
Where operation is the specific action to perform on Docker.
Configuring Options
Camel components are configured on two separate levels:
-
component level
-
endpoint level
Configuring Component Options
At the component level, you set general and shared configurations that are, then, inherited by the endpoints. It is the highest configuration level.
For example, a component may have security settings, credentials for authentication, urls for network connection and so forth.
Some components only have a few options, and others may have many. Because components typically have pre-configured defaults that are commonly used, then you may often only need to configure a few options on a component; or none at all.
You can configure components using:
-
the Component DSL.
-
in a configuration file (
application.properties
,*.yaml
files, etc). -
directly in the Java code.
Configuring Endpoint Options
You usually spend more time setting up endpoints because they have many options. These options help you customize what you want the endpoint to do. The options are also categorized into whether the endpoint is used as a consumer (from), as a producer (to), or both.
Configuring endpoints is most often done directly in the endpoint URI as path and query parameters. You can also use the Endpoint DSL and DataFormat DSL as a type safe way of configuring endpoints and data formats in Java.
A good practice when configuring options is to use Property Placeholders.
Property placeholders provide a few benefits:
-
They help prevent using hardcoded urls, port numbers, sensitive information, and other settings.
-
They allow externalizing the configuration from the code.
-
They help the code to become more flexible and reusable.
The following two sections list all the options, firstly for the component followed by the endpoint.
Component Options
The Docker component supports 21 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
To use the shared docker configuration. | DockerConfiguration | ||
Email address associated with the user. | String | ||
Required Docker host. | localhost | String | |
Docker port. | 2375 | Integer | |
Request timeout for response (in seconds). | Integer | ||
Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions (if possible) occurred while the Camel consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. Important: This is only possible if the 3rd party component allows Camel to be alerted if an exception was thrown. Some components handle this internally only, and therefore bridgeErrorHandler is not possible. In other situations we may improve the Camel component to hook into the 3rd party component and make this possible for future releases. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored. | false | boolean | |
Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing. | false | boolean | |
Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc. | true | boolean | |
The fully qualified class name of the DockerCmdExecFactory implementation to use. | com.github.dockerjava.netty.NettyDockerCmdExecFactory | String | |
Whether to follow redirect filter. | false | boolean | |
Whether to use logging filter. | false | boolean | |
Maximum route connections. | 100 | Integer | |
Maximum total connections. | 100 | Integer | |
Additional configuration parameters as key/value pairs. | Map | ||
Server address for docker registry. | String | ||
Socket connection mode. | true | boolean | |
Location containing the SSL certificate chain. | String | ||
Password to authenticate with. | String | ||
Use HTTPS communication. | false | boolean | |
Check TLS. | false | boolean | |
User name to authenticate with. | String |
Endpoint Options
The Docker endpoint is configured using URI syntax:
docker:operation
With the following path and query parameters:
Path Parameters (1 parameters)
Name | Description | Default | Type |
---|---|---|---|
Required Which operation to use. Enum values:
| DockerOperation |
Query Parameters (21 parameters)
Name | Description | Default | Type |
---|---|---|---|
Email address associated with the user. | String | ||
Required Docker host. | localhost | String | |
Docker port. | 2375 | Integer | |
Request timeout for response (in seconds). | Integer | ||
Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions (if possible) occurred while the Camel consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. Important: This is only possible if the 3rd party component allows Camel to be alerted if an exception was thrown. Some components handle this internally only, and therefore bridgeErrorHandler is not possible. In other situations we may improve the Camel component to hook into the 3rd party component and make this possible for future releases. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored. | false | boolean | |
To let the consumer use a custom ExceptionHandler. Notice if the option bridgeErrorHandler is enabled then this option is not in use. By default the consumer will deal with exceptions, that will be logged at WARN or ERROR level and ignored. | ExceptionHandler | ||
Sets the exchange pattern when the consumer creates an exchange. Enum values:
| ExchangePattern | ||
Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing. | false | boolean | |
The fully qualified class name of the DockerCmdExecFactory implementation to use. | com.github.dockerjava.netty.NettyDockerCmdExecFactory | String | |
Whether to follow redirect filter. | false | boolean | |
Whether to use logging filter. | false | boolean | |
Maximum route connections. | 100 | Integer | |
Maximum total connections. | 100 | Integer | |
Additional configuration parameters as key/value pairs. | Map | ||
Server address for docker registry. | String | ||
Socket connection mode. | true | boolean | |
Location containing the SSL certificate chain. | String | ||
Password to authenticate with. | String | ||
Use HTTPS communication. | false | boolean | |
Check TLS. | false | boolean | |
User name to authenticate with. | String |
Message Headers
The Docker component supports 82 message header(s), which is/are listed below:
Name | Description | Default | Type |
---|---|---|---|
CamelDockerRequestTimeout (common) Constant: | The request timeout for response (in seconds). | Integer | |
Constant: | The location containing the SSL certificate chain. | String | |
Constant: | The docker host. | String | |
Constant: | The docker port. | Integer | |
CamelDockerMaxPerRouteConnections (common) Constant: | The maximum route connections. | Integer | |
CamelDockerMaxTotalConnections (common) Constant: | The maximum total connections. | Integer | |
Constant: | Use HTTPS communication. | false | Boolean |
Constant: | Check TLS. | false | Boolean |
CamelDockerSocketEnabled (common) Constant: | Socket connection mode. | true | Boolean |
CamelDockerCmdExecFactory (common) Constant: | The fully qualified class name of the DockerCmdExecFactory implementation to use. | String | |
Constant: | With label filter. | String | |
Constant: | With show all flag. | Boolean | |
CamelDockerContainerId (common) Constant: | The id of the container. | String | |
Constant: | The Image ID. | String | |
Constant: | The email address associated with the user. | String | |
Constant: | The password to authenticate with. | String | |
CamelDockerServerAddress (common) Constant: | The server address for docker registry. | String | |
Constant: | The user name to authenticate with. | String | |
Constant: | The registry. | String | |
CamelDockerRepository (common) Constant: | The repository. | String | |
Constant: | The tag. | String | |
Constant: | The image name. | String | |
Constant: | The term to search. | String | |
Constant: | With force flag. | Boolean | |
Constant: | With no prune flag. | Boolean | |
CamelDockerInitialRange (common) Constant: | The initial range. | Long | |
Constant: | With before. | String | |
Constant: | With limit. | Integer | |
Constant: | With show size flag. | Boolean | |
Constant: | With since. | String | |
CamelDockerRemoveVolumes (common) Constant: | With remove volumes flag. | Boolean | |
CamelDockerFollowStream (common) Constant: | With follow stream flag. | Boolean | |
Constant: | With logs flag. | Boolean | |
Constant: | With stdErr flag. | Boolean | |
Constant: | With stdOut flag. | Boolean | |
CamelDockerTimestamps (common) Constant: | With timestamps flag. | Boolean | |
Constant: | With Tail. | Integer | |
Constant: | With tail all flag. | Boolean | |
Constant: | The host path. | String | |
Constant: | The resource. | String | |
CamelDockerContainerIdDiff (common) Constant: | With container id for diff container request. | String | |
Constant: | With timeout. | Integer | |
Constant: | With signal. | String | |
Constant: | With ps args. | String | |
Constant: | With no cache flag. | Boolean | |
Constant: | With quiet flag. | Boolean | |
Constant: | With remove flag. | Boolean | |
CamelDockerAttachStdErr (common) Constant: | With attach StdErr flag. | Boolean | |
CamelDockerAttachStdIn (common) Constant: | With attach StdIn flag. | Boolean | |
CamelDockerAttachStdOut (common) Constant: | With attach StdOut flag. | Boolean | |
Constant: | The author. | String | |
Constant: | With cmd. | String or String[] | |
CamelDockerDisableNetwork (common) Constant: | With disable network flag. | Boolean | |
Constant: | With env. | String or String[] | |
CamelDockerExposedPorts (common) Constant: | The exposed ports. | ExposedPorts or ExposedPorts[] | |
Constant: | The hostname. | String | |
Constant: | The message. | String | |
Constant: | With memory. | Integer | |
CamelDockerMemorySwap (common) Constant: | With memory swap. | Long or Integer | |
Constant: | With open StdIn flag. | Boolean | |
Constant: | With pause flag. | Boolean | |
Constant: | With port specs. | String or String[] | |
Constant: | With StdIn in once flag. | Boolean | |
Constant: | With TTY flag. | Boolean | |
Constant: | With user. | String | |
Constant: | With volumes. | Volume or Volume[] | |
CamelDockerWorkingDir (common) Constant: | With working directory. | String | |
Constant: | With CPU shares. | Integer | |
Constant: | With dns. | String or String[] | |
CamelDockerEntryPoint (common) Constant: | With entrypoint. | String or String[] | |
CamelDockerHostConfig (common) Constant: | With host config. | HostConfig | |
Constant: | The docker image. | String | |
CamelDockerMemoryLimit (common) Constant: | With memory limit. | Long | |
Constant: | With StdIn in open flag. | Boolean | |
CamelDockerVolumesFrom (common) Constant: | With volumes from. | VolumesFrom or VolumesFrom[] | |
CamelDockerDomainName (common) Constant: | With domain name. | String | |
Constant: | With binds. | Bind or Bind[] | |
Constant: | With cap add. | Capability or Capability[] | |
Constant: | With cap drop. | Capability or Capability[] | |
Constant: | The network name. | String | |
Constant: | With detach flag. | Boolean | |
Constant: | The Exec ID. | String |
Examples
The following example consumes events from Docker:
from("docker://events?host=192.168.59.103&port=2375").to("log:event");
The following example queries Docker for system-wide information
from("docker://info?host=192.168.59.103&port=2375").to("log:info");
Dependencies
To use Docker in your Camel routes, you need to add a dependency on camel-docker, which implements the component.
If you use Maven, you can add the following to your pom.xml, substituting the version number for the latest and greatest release (see the download page for the latest versions).
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-docker</artifactId>
<version>x.x.x</version>
</dependency>
Spring Boot Auto-Configuration
When using docker with Spring Boot make sure to use the following Maven dependency to have support for auto configuration:
<dependency>
<groupId>org.apache.camel.springboot</groupId>
<artifactId>camel-docker-starter</artifactId>
<version>x.x.x</version>
<!-- use the same version as your Camel core version -->
</dependency>
The component supports 22 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc. | true | Boolean | |
Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions (if possible) occurred while the Camel consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. Important: This is only possible if the 3rd party component allows Camel to be alerted if an exception was thrown. Some components handle this internally only, and therefore bridgeErrorHandler is not possible. In other situations we may improve the Camel component to hook into the 3rd party component and make this possible for future releases. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored. | false | Boolean | |
Location containing the SSL certificate chain. | String | ||
The fully qualified class name of the DockerCmdExecFactory implementation to use. | com.github.dockerjava.netty.NettyDockerCmdExecFactory | String | |
To use the shared docker configuration. The option is a org.apache.camel.component.docker.DockerConfiguration type. | DockerConfiguration | ||
Email address associated with the user. | String | ||
Whether to enable auto configuration of the docker component. This is enabled by default. | Boolean | ||
Whether to follow redirect filter. | false | Boolean | |
Docker host. | localhost | String | |
Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing. | false | Boolean | |
Whether to use logging filter. | false | Boolean | |
Maximum route connections. | 100 | Integer | |
Maximum total connections. | 100 | Integer | |
Additional configuration parameters as key/value pairs. | Map | ||
Password to authenticate with. | String | ||
Docker port. | 2375 | Integer | |
Request timeout for response (in seconds). | Integer | ||
Use HTTPS communication. | false | Boolean | |
Server address for docker registry. | String | ||
Socket connection mode. | true | Boolean | |
Check TLS. | false | Boolean | |
User name to authenticate with. | String |