Camel Components

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 the following options which are listed below.

Name Description Default Type

configuration (common)

The shared configuration of the component, which each endpoint copies and then applies its own options to.

DockerConfiguration

email (common)

Email address associated with the user.

String

host (common)

Required Docker host. In socket mode (socket=true), the path of the unix socket of the Docker daemon, where the default localhost means /var/run/docker.sock. A host with a tcp:// or unix:// scheme (such as tcp://myhost:2376 or unix:///var/run/docker.sock) is used as is, and then the port and socket options are not used.

localhost

String

port (common)

The TCP port of the Docker daemon. Not used in socket mode, or when the host is a tcp:// or unix:// URL.

2375

Integer

requestTimeout (common)

The timeout in milliseconds to connect to the Docker daemon, and with JerseyDockerCmdExecFactory also to wait for data of a response. Not used with a cmdExecFactory other than NettyDockerCmdExecFactory and JerseyDockerCmdExecFactory. When not set, the defaults of the transport apply.

Integer

bridgeErrorHandler (consumer)

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

lazyStartProducer (producer)

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

autowiredEnabled (advanced)

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

cmdExecFactory (advanced)

The fully qualified class name of the DockerCmdExecFactory implementation of docker-java that sends the requests to the Docker daemon, such as com.github.dockerjava.netty.NettyDockerCmdExecFactory (the default) or com.github.dockerjava.jaxrs.JerseyDockerCmdExecFactory.

com.github.dockerjava.netty.NettyDockerCmdExecFactory

String

followRedirectFilter (advanced)

Deprecated Whether to follow redirect filter. Deprecation note: Not used: nothing reads this option when the Docker client is built.

false

boolean

loggingFilter (advanced)

Deprecated Whether to use logging filter. Deprecation note: Not used: nothing reads this option when the Docker client is built.

false

boolean

maxPerRouteConnections (advanced)

Not used: the component does not pass this value to the DockerCmdExecFactory.

100

Integer

maxTotalConnections (advanced)

Not used: the component does not pass this value to the DockerCmdExecFactory.

100

Integer

parameters (advanced)

The parameters of the endpoint URI that are not options, such as containerId=myContainer. The component sets them. Each one is the fallback for the CamelDocker header of the same name, such as containerId for CamelDockerContainerId.

Map

serverAddress (advanced)

The server address of the Docker registry.

https://index.docker.io/v1/

String

socket (advanced)

Socket connection mode. When enabled, connects to the unix socket of the Docker daemon, whose path is given by the host option (the default localhost means /var/run/docker.sock), and the port is not used. When disabled, connects over TCP to the host and port.

false

boolean

allowConnectionAndCredentialsFromHeaders (security)

Whether to allow overriding the connection and credential settings of the endpoint with the CamelDockerHost, CamelDockerPort, CamelDockerSocketEnabled, CamelDockerSecure, CamelDockerTlsVerify, CamelDockerCertPath, CamelDockerCmdExecFactory, CamelDockerUsername, CamelDockerPassword and CamelDockerServerAddress headers. Disabled by default; enable it only when the header source is trusted, since it lets a message choose the Docker daemon that the client connects to and how, and the registry that receives the username and password of the endpoint.

false

boolean

certPath (security)

The directory with the certificates and the key of the client (ca.pem, cert.pem and key.pem), used when secure is enabled.

String

password (security)

Password to authenticate with.

String

secure (security)

Whether to connect to the Docker daemon with HTTPS, using the certificates in certPath, which is then required.

false

boolean

tlsVerify (security)

Check TLS.

false

boolean

username (security)

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

Name Description Default Type

operation (common)

Required The operation to perform: events and stats for the consumer, the others for the producer.

Enum values:

  • events

  • stats

  • auth

  • info

  • ping

  • version

  • imagebuild

  • imagecreate

  • imageinspect

  • imagelist

  • imagepull

  • imagepush

  • imageremove

  • imagesearch

  • imagetag

  • containerattach

  • containercommit

  • containercopyfile

  • containercreate

  • containerdiff

  • inspectcontainer

  • containerkill

  • containerlist

  • containerlog

  • containerpause

  • containerrestart

  • containerremove

  • containerstart

  • containerstop

  • containertop

  • containerunpause

  • containerwait

  • execcreate

  • execstart

  • networkconnect

  • networkcreate

  • networkremove

DockerOperation

Query Parameters

Name Description Default Type

email (common)

Email address associated with the user.

String

host (common)

Required Docker host. In socket mode (socket=true), the path of the unix socket of the Docker daemon, where the default localhost means /var/run/docker.sock. A host with a tcp:// or unix:// scheme (such as tcp://myhost:2376 or unix:///var/run/docker.sock) is used as is, and then the port and socket options are not used.

localhost

String

port (common)

The TCP port of the Docker daemon. Not used in socket mode, or when the host is a tcp:// or unix:// URL.

2375

Integer

requestTimeout (common)

The timeout in milliseconds to connect to the Docker daemon, and with JerseyDockerCmdExecFactory also to wait for data of a response. Not used with a cmdExecFactory other than NettyDockerCmdExecFactory and JerseyDockerCmdExecFactory. When not set, the defaults of the transport apply.

Integer

bridgeErrorHandler (consumer (advanced))

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

exceptionHandler (consumer (advanced))

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

exchangePattern (consumer (advanced))

Sets the exchange pattern when the consumer creates an exchange.

Enum values:

  • InOnly

  • InOut

ExchangePattern

lazyStartProducer (producer (advanced))

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

cmdExecFactory (advanced)

The fully qualified class name of the DockerCmdExecFactory implementation of docker-java that sends the requests to the Docker daemon, such as com.github.dockerjava.netty.NettyDockerCmdExecFactory (the default) or com.github.dockerjava.jaxrs.JerseyDockerCmdExecFactory.

com.github.dockerjava.netty.NettyDockerCmdExecFactory

String

followRedirectFilter (advanced)

Deprecated Whether to follow redirect filter. Deprecation note: Not used: nothing reads this option when the Docker client is built.

false

boolean

loggingFilter (advanced)

Deprecated Whether to use logging filter. Deprecation note: Not used: nothing reads this option when the Docker client is built.

false

boolean

maxPerRouteConnections (advanced)

Not used: the component does not pass this value to the DockerCmdExecFactory.

100

Integer

maxTotalConnections (advanced)

Not used: the component does not pass this value to the DockerCmdExecFactory.

100

Integer

parameters (advanced)

The parameters of the endpoint URI that are not options, such as containerId=myContainer. The component sets them. Each one is the fallback for the CamelDocker header of the same name, such as containerId for CamelDockerContainerId.

Map

serverAddress (advanced)

The server address of the Docker registry.

https://index.docker.io/v1/

String

socket (advanced)

Socket connection mode. When enabled, connects to the unix socket of the Docker daemon, whose path is given by the host option (the default localhost means /var/run/docker.sock), and the port is not used. When disabled, connects over TCP to the host and port.

false

boolean

allowConnectionAndCredentialsFromHeaders (security)

Whether to allow overriding the connection and credential settings of the endpoint with the CamelDockerHost, CamelDockerPort, CamelDockerSocketEnabled, CamelDockerSecure, CamelDockerTlsVerify, CamelDockerCertPath, CamelDockerCmdExecFactory, CamelDockerUsername, CamelDockerPassword and CamelDockerServerAddress headers. Disabled by default; enable it only when the header source is trusted, since it lets a message choose the Docker daemon that the client connects to and how, and the registry that receives the username and password of the endpoint.

false

boolean

certPath (security)

The directory with the certificates and the key of the client (ca.pem, cert.pem and key.pem), used when secure is enabled.

String

password (security)

Password to authenticate with.

String

secure (security)

Whether to connect to the Docker daemon with HTTPS, using the certificates in certPath, which is then required.

false

boolean

tlsVerify (security)

Check TLS.

false

boolean

username (security)

User name to authenticate with.

String

Message Headers

The Docker component supports the following message header(s), which is/are listed below:

Name Description Default Type

CamelDockerRequestTimeout (common)

Constant: DOCKER_API_REQUEST_TIMEOUT

The timeout in milliseconds to connect to the Docker daemon, and with JerseyDockerCmdExecFactory also to wait for data of a response, as the requestTimeout option.

Integer

CamelDockerCertPath (common)

Constant: DOCKER_CERT_PATH

The directory with the certificates and the key of the client, used when secure is enabled. This header is ignored unless the endpoint enables allowConnectionAndCredentialsFromHeaders=true (disabled by default).

String

CamelDockerHost (common)

Constant: DOCKER_HOST

The docker host. This header is ignored unless the endpoint enables allowConnectionAndCredentialsFromHeaders=true (disabled by default).

String

CamelDockerPort (common)

Constant: DOCKER_PORT

The docker port. This header is ignored unless the endpoint enables allowConnectionAndCredentialsFromHeaders=true (disabled by default).

Integer

CamelDockerMaxPerRouteConnections (common)

Constant: DOCKER_MAX_PER_ROUTE_CONNECTIONS

Not used, as the maxPerRouteConnections option.

Integer

CamelDockerMaxTotalConnections (common)

Constant: DOCKER_MAX_TOTAL_CONNECTIONS

Not used, as the maxTotalConnections option.

Integer

CamelDockerSecure (common)

Constant: DOCKER_SECURE

Whether to connect to the Docker daemon with HTTPS. This header is ignored unless the endpoint enables allowConnectionAndCredentialsFromHeaders=true (disabled by default).

false

Boolean

CamelDockerTlsVerify (common)

Constant: DOCKER_TLSVERIFY

Check TLS. This header is ignored unless the endpoint enables allowConnectionAndCredentialsFromHeaders=true (disabled by default).

false

Boolean

CamelDockerSocketEnabled (common)

Constant: DOCKER_SOCKET_ENABLED

Socket connection mode: connect to the unix socket of the Docker daemon, whose path is given by the host (the default localhost means /var/run/docker.sock). This header is ignored unless the endpoint enables allowConnectionAndCredentialsFromHeaders=true (disabled by default).

false

Boolean

CamelDockerCmdExecFactory (common)

Constant: DOCKER_CMD_EXEC_FACTORY

The fully qualified class name of the DockerCmdExecFactory implementation to use. This header is ignored unless the endpoint enables allowConnectionAndCredentialsFromHeaders=true (disabled by default).

String

CamelDockerFilter (common)

Constant: DOCKER_FILTER

For imagelist: only list the images with this label, in the form key or key=value.

String

CamelDockerShowAll (common)

Constant: DOCKER_SHOW_ALL

For imagelist: also list the intermediate images. For containerlist: list all containers, not only the running ones.

Boolean

CamelDockerContainerId (common)

Constant: DOCKER_CONTAINER_ID

The id or name of the container of the container operations, execcreate and networkconnect. The stats consumer reads it from the containerId parameter of the endpoint URI.

String

CamelDockerImageId (common)

Constant: DOCKER_IMAGE_ID

The id or name of the image for imageinspect, imageremove and imagetag.

String

CamelDockerEmail (common)

Constant: DOCKER_EMAIL

The email address associated with the user.

String

CamelDockerPassword (common)

Constant: DOCKER_PASSWORD

The password to authenticate with. This header is ignored unless the endpoint enables allowConnectionAndCredentialsFromHeaders=true (disabled by default).

String

CamelDockerServerAddress (common)

Constant: DOCKER_SERVER_ADDRESS

The server address of the Docker registry. This header is ignored unless the endpoint enables allowConnectionAndCredentialsFromHeaders=true (disabled by default).

String

CamelDockerUsername (common)

Constant: DOCKER_USERNAME

The user name to authenticate with. This header is ignored unless the endpoint enables allowConnectionAndCredentialsFromHeaders=true (disabled by default).

String

CamelDockerRegistry (common)

Constant: DOCKER_REGISTRY

The registry.

String

CamelDockerRepository (common)

Constant: DOCKER_REPOSITORY

The repository (image name) for imagecreate, imagepull, imagetag and containercommit.

String

CamelDockerTag (common)

Constant: DOCKER_TAG

The tag for imagepull, imagepush, imagetag and containercommit. For imagebuild, the name and optional tag of the built image, in the form name:tag.

String

CamelDockerName (common)

Constant: DOCKER_NAME

The image name for imagepush. For containercreate, the name of the container.

String

CamelDockerTerm (common)

Constant: DOCKER_TERM

The term to search for with imagesearch.

String

CamelDockerForce (common)

Constant: DOCKER_FORCE

For imageremove and imagetag: whether to force the operation. For containerremove: whether to kill and remove a running container.

Boolean

CamelDockerNoPrune (common)

Constant: DOCKER_NO_PRUNE

For imageremove: whether to keep the untagged parent images.

Boolean

CamelDockerInitialRange (common)

Constant: DOCKER_INITIAL_RANGE

The time in milliseconds before the start of the events consumer from which it also receives the past events.

Long

CamelDockerBefore (common)

Constant: DOCKER_BEFORE

For containerlist: only list the containers created before the container with this id or name, including the ones that are not running.

String

CamelDockerLimit (common)

Constant: DOCKER_LIMIT

For containerlist: only list this number of the last created containers, including the ones that are not running.

Integer

CamelDockerShowSize (common)

Constant: DOCKER_SHOW_SIZE

For containerlist: whether to include the sizes of the containers.

Boolean

CamelDockerSince (common)

Constant: DOCKER_SINCE

For containerlist: only list the containers created after the container with this id or name, including the ones that are not running.

String

CamelDockerRemoveVolumes (common)

Constant: DOCKER_REMOVE_VOLUMES

For containerremove: whether to also remove the anonymous volumes of the container.

Boolean

CamelDockerFollowStream (common)

Constant: DOCKER_FOLLOW_STREAM

For containerattach and containerlog: whether to keep the stream open, so the operation waits until the container stops.

Boolean

CamelDockerLogs (common)

Constant: DOCKER_LOGS

For containerattach: whether to also return the output that the container wrote before the attach.

Boolean

CamelDockerStdErr (common)

Constant: DOCKER_STD_ERR

For containerattach and containerlog: whether to include the output of stderr.

Boolean

CamelDockerStdOut (common)

Constant: DOCKER_STD_OUT

For containerattach and containerlog: whether to include the output of stdout.

Boolean

CamelDockerTimestamps (common)

Constant: DOCKER_TIMESTAMPS

For containerlog: whether to start each line with its timestamp. Not used by containerattach.

Boolean

CamelDockerTail (common)

Constant: DOCKER_TAIL

For containerlog: the number of lines to return from the end of the log.

Integer

CamelDockerTailAll (common)

Constant: DOCKER_TAIL_ALL

For containerlog: whether to return all the lines of the log, in place of CamelDockerTail.

Boolean

CamelDockerHostPath (common)

Constant: DOCKER_HOST_PATH

Not used: docker-java does not send the host path of containercopyfile.

String

CamelDockerResource (common)

Constant: DOCKER_RESOURCE

For containercopyfile: the path of the file or directory in the container, which the operation returns as a tar archive.

String

CamelDockerContainerIdDiff (common)

Constant: DOCKER_CONTAINER_ID_DIFF

For containerdiff: the id or name of the container, in place of CamelDockerContainerId, which is still required.

String

CamelDockerTimeout (common)

Constant: DOCKER_TIMEOUT

For containerstop and containerrestart: the number of seconds to wait for the container to stop before it is killed.

Integer

CamelDockerSignal (common)

Constant: DOCKER_SIGNAL

For containerkill: the signal to send to the container, such as SIGTERM. Docker sends SIGKILL by default.

String

CamelDockerPsArgs (common)

Constant: DOCKER_PS_ARGS

For containertop: the arguments of the ps command, such as aux. Docker uses -ef by default.

String

CamelDockerNoCache (common)

Constant: DOCKER_NO_CACHE

For imagebuild: whether to build without the build cache.

Boolean

CamelDockerQuiet (common)

Constant: DOCKER_QUIET

For imagebuild: whether to suppress the verbose build output.

Boolean

CamelDockerRemove (common)

Constant: DOCKER_REMOVE

For imagebuild: whether to remove the intermediate containers after a successful build. Docker removes them by default.

Boolean

CamelDockerAttachStdErr (common)

Constant: DOCKER_ATTACH_STD_ERR

For containercommit, containercreate and execcreate: whether to attach stderr.

Boolean

CamelDockerAttachStdIn (common)

Constant: DOCKER_ATTACH_STD_IN

For containercommit, containercreate and execcreate: whether to attach stdin.

Boolean

CamelDockerAttachStdOut (common)

Constant: DOCKER_ATTACH_STD_OUT

For containercommit, containercreate and execcreate: whether to attach stdout.

Boolean

CamelDockerAuthor (common)

Constant: DOCKER_AUTHOR

For containercommit: the author of the image.

String

CamelDockerCmd (common)

Constant: DOCKER_CMD

For containercommit, containercreate and execcreate: the command to run, as a String[] or a String with the arguments separated by semicolons.

String or String[]

CamelDockerDisableNetwork (common)

Constant: DOCKER_DISABLE_NETWORK

For containercommit and containercreate: whether to disable the networking of the container.

Boolean

CamelDockerEnv (common)

Constant: DOCKER_ENV

For containercommit and containercreate: the environment variables in the form NAME=value, as a String[] or a String with the variables separated by semicolons.

String or String[]

CamelDockerExposedPorts (common)

Constant: DOCKER_EXPOSED_PORTS

The ports that the container exposes: an ExposedPorts for containercommit, an ExposedPort or ExposedPort[] for containercreate.

ExposedPort[]

CamelDockerHostname (common)

Constant: DOCKER_HOSTNAME

For containercommit and containercreate: the host name of the container.

String

CamelDockerMessage (common)

Constant: DOCKER_MESSAGE

For containercommit: the commit message.

String

CamelDockerMemory (common)

Constant: DOCKER_MEMORY

For containercommit: the memory limit in bytes.

Integer

CamelDockerMemorySwap (common)

Constant: DOCKER_MEMORY_SWAP

For containercommit and containercreate: the limit of the memory plus the swap in bytes.

Long or Integer

CamelDockerOpenStdIn (common)

Constant: DOCKER_OPEN_STD_IN

For containercommit: whether to keep stdin open.

Boolean

CamelDockerPause (common)

Constant: DOCKER_PAUSE

For containercommit: whether to pause the container while it is committed.

Boolean

CamelDockerPortSpecs (common)

Constant: DOCKER_PORT_SPECS

For containercommit and containercreate: the port specs, as a String[] or a String with the specs separated by semicolons.

String or String[]

CamelDockerStdInOnce (common)

Constant: DOCKER_STD_IN_ONCE

For containercommit and containercreate: whether to close stdin after the first attached client disconnects.

Boolean

CamelDockerTty (common)

Constant: DOCKER_TTY

For containercommit, containercreate, execcreate and execstart: whether to allocate a pseudo-TTY.

Boolean

CamelDockerUser (common)

Constant: DOCKER_USER

For containercommit and containercreate: the user that runs the commands in the container.

String

CamelDockerVolumes (common)

Constant: DOCKER_VOLUMES

The volumes of the container: a Volumes for containercommit, a Volume or Volume[] for containercreate.

Volume[]

CamelDockerWorkingDir (common)

Constant: DOCKER_WORKING_DIR

For containercommit and containercreate: the working directory of the commands in the container.

String

CamelDockerCpuShares (common)

Constant: DOCKER_CPU_SHARES

For containercreate: the CPU shares (relative weight) of the container.

Integer

CamelDockerDns (common)

Constant: DOCKER_DNS

For containercreate: the DNS servers, as a String[] or a String with the servers separated by semicolons.

String or String[]

CamelDockerEntryPoint (common)

Constant: DOCKER_ENTRYPOINT

For containercreate: the entrypoint, as a String[] or a String.

String or String[]

CamelDockerHostConfig (common)

Constant: DOCKER_HOST_CONFIG

For containercreate: the host configuration of the container. It replaces the one that CamelDockerCapAdd, CamelDockerCapDrop, CamelDockerCpuShares and CamelDockerDns configure.

HostConfig

CamelDockerImage (common)

Constant: DOCKER_IMAGE

For containercreate: the image to create the container from.

String

CamelDockerMemoryLimit (common)

Constant: DOCKER_MEMORY_LIMIT

For containercreate: the memory limit of the container in bytes.

Long

CamelDockerStdInOpen (common)

Constant: DOCKER_STD_IN_OPEN

For containercreate: whether to keep stdin open.

Boolean

CamelDockerVolumesFrom (common)

Constant: DOCKER_VOLUMES_FROM

For containercreate: the containers whose volumes to mount, as a VolumesFrom or VolumesFrom[].

VolumesFrom[]

CamelDockerDomainName (common)

Constant: DOCKER_DOMAIN_NAME

For containercreate: the domain name of the container.

String

CamelDockerBinds (common)

Constant: DOCKER_BINDS

For containercreate: the bind mounts of the container, as a Bind or Bind[].

Bind[]

CamelDockerCapAdd (common)

Constant: DOCKER_CAP_ADD

For containercreate: the Linux capabilities to add to the container, as a Capability or Capability[].

Capability[]

CamelDockerCapDrop (common)

Constant: DOCKER_CAP_DROP

For containercreate: the Linux capabilities to drop from the container, as a Capability or Capability[].

Capability[]

CamelDockerNetwork (common)

Constant: DOCKER_NETWORK

For networkcreate: the name of the network. For networkremove and networkconnect: the id or name of the network.

String

CamelDockerDetach (common)

Constant: DOCKER_DETACH

For execstart: whether to detach from the command, so the operation does not wait for its output.

Boolean

CamelDockerExecId (common)

Constant: DOCKER_EXEC_ID

For execstart: the id of the exec instance that execcreate created.

String

Message Body

The message body at each side of the Docker component: Consumer is the body of the messages the consumer creates, Consumer reply the bodies a consumer that answers its caller can reply with, Producer input the bodies the producer can send or write, and Producer output the body after the producer.

Side Body Description

Consumer

pojo

The object of docker-java for each item of the stream: an Event of the daemon with events, the Statistics of the container in CamelDockerContainerId with stats.

  • With operation=events: pojo (com.github.dockerjava.api.model.Event)

  • With operation=stats: pojo (com.github.dockerjava.api.model.Statistics)

Producer input

any

Not used by most operations, which take their input from the options and headers, such as the container in CamelDockerContainerId. imagecreate reads the image as a stream; imagebuild needs the build context as a tar archive (an InputStream, a byte[] or another body that converts to an InputStream) or as a java.io.File of the Dockerfile or its directory, and fails without one.

  • With operation=imagecreate: stream, bytes, text or file

  • With operation=imagebuild: stream, bytes or file

Producer output

pojo, list, text, stream, value or unchanged

The response of docker-java for the operation, such as the Version of version and a List of Containers for containerlist; the operations without a response, such as ping and containerstart, keep the body. The streaming operations wait until the stream is done: containerattach, containerlog and execstart give the output of stdout and stderr as text, containerwait the exit code of the container, imagebuild the id of the built image, imagepull and imagepush the last item of the progress; a failed build, pull or push fails the exchange.

  • With operation=auth: pojo (com.github.dockerjava.api.model.AuthResponse)

  • With operation=info: pojo (com.github.dockerjava.api.model.Info)

  • With operation=ping: unchanged

  • With operation=version: pojo (com.github.dockerjava.api.model.Version)

  • With operation=imagebuild: text (java.lang.String)

  • With operation=imagecreate: pojo (com.github.dockerjava.api.command.CreateImageResponse)

  • With operation=imageinspect: pojo (com.github.dockerjava.api.command.InspectImageResponse)

  • With operation=imagelist: list

  • With operation=imagepull: pojo (com.github.dockerjava.api.model.PullResponseItem)

  • With operation=imagepush: pojo (com.github.dockerjava.api.model.PushResponseItem)

  • With operation=imageremove: unchanged

  • With operation=imagesearch: list

  • With operation=imagetag: unchanged

  • With operation=containerattach: text (java.lang.String)

  • With operation=containercommit: text (java.lang.String)

  • With operation=containercopyfile: stream

  • With operation=containercreate: pojo (com.github.dockerjava.api.command.CreateContainerResponse)

  • With operation=containerdiff: list

  • With operation=inspectcontainer: pojo (com.github.dockerjava.api.command.InspectContainerResponse)

  • With operation=containerkill: unchanged

  • With operation=containerlist: list

  • With operation=containerlog: text (java.lang.String)

  • With operation=containerpause: unchanged

  • With operation=containerrestart: unchanged

  • With operation=containerremove: unchanged

  • With operation=containerstart: unchanged

  • With operation=containerstop: unchanged

  • With operation=containertop: pojo (com.github.dockerjava.api.command.TopContainerResponse)

  • With operation=containerunpause: unchanged

  • With operation=containerwait: value (java.lang.Integer)

  • With operation=execcreate: pojo (com.github.dockerjava.api.command.ExecCreateCmdResponse)

  • With operation=execstart: text (java.lang.String)

  • With operation=networkconnect: unchanged

  • With operation=networkcreate: pojo (com.github.dockerjava.api.command.CreateNetworkResponse)

  • With operation=networkremove: unchanged

The bodies are the ones with the default options. A side that is not listed is not known, and tooling does not guess it. The carriers, the sides and the tools that use them are described in Message Body Types.

Usage

Connecting to the Docker daemon

By default, the component connects over TCP to host and port (tcp://localhost:2375). Docker does not open this TCP port by default; it has to be enabled in the configuration of the daemon.

To connect to the local unix socket of the daemon instead, set socket=true. In socket mode host is the path of the socket and port is not used. The default host localhost means /var/run/docker.sock:

from("timer:info?repeatCount=1")
    .to("docker:info?socket=true")
    .log("${body}");

For a socket in another place, set its path as the host, for example docker:info?socket=true&host=/run/user/1000/docker.sock.

The host can also be a full Docker host URL with a tcp:// or unix:// scheme, in the same form as the DOCKER_HOST environment variable, such as tcp://myhost:2376 or unix:///var/run/docker.sock. Such a host is used as is, and the port and socket options are not used. Windows named pipes (npipe://) are not supported by the Docker client of the component.

Header Strategy

All URI options can be passed as Header properties. Values found in a message header take precedence over URI parameters. A header property takes the form of a URI option prefixed with CamelDocker as shown below

URI Option Header Property

containerId

CamelDockerContainerId

The headers of the connection and credential settings are the exception: CamelDockerHost, CamelDockerPort, CamelDockerSocketEnabled, CamelDockerSecure, CamelDockerTlsVerify, CamelDockerCertPath, CamelDockerCmdExecFactory, CamelDockerUsername, CamelDockerPassword and CamelDockerServerAddress are ignored unless the endpoint sets allowConnectionAndCredentialsFromHeaders=true. Without this option, the producer connects to the Docker daemon of the endpoint, in the way the endpoint configures, and gives the username and password of the endpoint to the registry of the endpoint, whatever the headers of the message say.

Enable allowConnectionAndCredentialsFromHeaders only when the headers come from a trusted source, since with it a message chooses the Docker daemon that the client connects to and how (TLS, the client certificates and the DockerCmdExecFactory class), and the registry that receives the username and password of the endpoint. Set on the component, the option applies to all its endpoints.

The other headers, such as CamelDockerContainerId, still take precedence over the options of the endpoint. When the messages come from an untrusted producer through a consumer that does not filter out Camel* headers, remove these headers with removeHeaders("CamelDocker*") before the docker endpoint.

Registry authentication

The imagepull and imagepush operations send the username, password and email of the endpoint only for an image in the registry of serverAddress: the registry host and port of the image reference must match those of serverAddress. An image reference without a registry host, such as ubuntu or team/app, is on Docker Hub, which matches the default serverAddress (https://index.docker.io/v1/). An image in another registry is pulled or pushed without authentication, and so is every image when the endpoint has no username. To pull or push with authentication from several registries, use one endpoint per registry.

Streaming operations

The operations imagebuild, imagepull, imagepush, containerattach, containerlog, containerwait and execstart wait until Docker has finished, and set the result as the message body:

  • imagebuild: the id of the built image. The body is the build context: a tar archive as an InputStream, a byte[] or another body that converts to an InputStream, or a java.io.File of the Dockerfile or its directory.

  • containerattach, containerlog and execstart: the output of stdout and stderr as a String.

  • containerwait: the exit code of the container as an Integer.

  • imagepull and imagepush: the last PullResponseItem or PushResponseItem of the progress.

When the operation fails, for example a build step that fails, the exchange fails.

With followStream=true, containerattach and containerlog wait until the container stops.

Examples

The following example consumes events from Docker:

  • Java

  • XML

  • YAML

from("docker://events?host=192.168.59.103&port=2375").to("log:event");
<route>
  <from uri="docker://events?host=192.168.59.103&amp;port=2375"/>
  <to uri="log:event"/>
</route>
- route:
    from:
      uri: docker://events
      parameters:
        host: 192.168.59.103
        port: 2375
      steps:
        - to:
            uri: log:event

The following example queries Docker for system-wide information

  • Java

  • XML

  • YAML

from("docker://info?host=192.168.59.103&port=2375").to("log:info");
<route>
  <from uri="docker://info?host=192.168.59.103&amp;port=2375"/>
  <to uri="log:info"/>
</route>
- route:
    from:
      uri: docker://info
      parameters:
        host: 192.168.59.103
        port: 2375
      steps:
        - to:
            uri: 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>