We have a requirement to setup multiple jenkins instances on limited number of host machines.
To achieve this, I've setup Docker Swarm on two servers.
On the "master" node, I use terraform to create and manage docker services.
When I create the services manually, the container automatically gets spawned on worker node. When I create a service with 2 replicas, the containers are created on both nodes as they should be.
However when I use terraform code to create and manage the service, the containers are never created on worker node. Even when I setup 2 replicas, both are created on the master node.
The main.tf file used to create the service is provided here.
resource "docker_service" "jenkins_service" {
name = var.project_name
task_spec {
container_spec {
image = docker_image.jenkins_image.name
mounts {
target = "/var/jenkins_name"
source = docker_volume.jenkins_volume.name
type = "volume"
}
mounts {
source = "/var/run/docker.sock"
target = "/var/run/docker.sock"
type = "bind"
}
}
networks = ["${docker_network.jenkins_network.name}"]
}
endpoint_spec {
ports {
target_port = "8080"
published_port = var.web_interface_port
publish_mode = "ingress"
name = "WEB_INTERFACE"
}
ports {
target_port = "50000"
published_port = var.api_interface_port
publish_mode = "ingress"
name = "API_INTERFACE"
}
}
}
I don't know what I am doing wrong here. Any help will be much appreciated
Regards.