Extend documentation by
@@ -312,7 +312,7 @@ task removeContainer(type: DockerRemoveContainer) {
== Executing functional tests against a running container
The following example code demonstrates how to build a Docker image from a Dockerfile, starts up a container for this
-image and exercises functional tests agains the running container. At the end of this operation, the container is stopped.
+image and exercises functional tests against the running container. At the end of this operation, the container is stopped.
[source,groovy]
----
@@ -347,6 +347,52 @@ task functionalTestMyApp(type: Test) {
}
----
+=== Linking with other containers
+
+In many situations your container does not start without dependencies like database. In that case you may wish using traditional linking:
+
+[source,groovy]
+----
+apply plugin: 'com.bmuschko.docker-remote-api'
+
+import com.bmuschko.gradle.docker.tasks.container.*
+import com.bmuschko.gradle.docker.tasks.image.*
+
+task buildMyAppImage(type: DockerBuildImage) {
+ inputDir = file('docker/myapp')
+ tag = 'test/myapp'
+}
+
+task createDBContainer(type: DockerCreateContainer) {
+ targetImageId { 'postgres:latest' }
+ containerName "docker_auto_${buildMyAppImage.buildTagName}"
+}
+
+task createMyAppContainer(type: DockerCreateContainer, dependsOn: [buildMyAppImage, createDBContainer]) {
+ targetImageId { buildMyAppImage.getImageId() }
+ portBindings = ['8080:8080']
+
+ doFirst{ // doFirst required! #319
+ links = [ "${createDBContainer.getContainerId()}:database" ] // `database` there will be host used by application to DB connect
+ }
+
+ // If you use Systemd in containers you should also add lines: (#320):
+ binds = [ '/sys/fs/cgroup': '/sys/fs/cgroup' ]
+ tty = true
+}
+
+task startMyAppContainer(type: DockerStartContainer, dependsOn: createMyAppContainer) {
+ targetContainerId { createMyAppContainer.getContainerId() }
+}
+
+task stopMyAppContainer(type: DockerStopContainer) {
+ targetContainerId { createMyAppContainer.getContainerId() }
+}
+
+task functionalTestMyApp(type: Test, dependsOn: startMyAppContainer) {
+ finalizedBy stopMyAppContainer
+}
+----
== Java application plugin
