I am trying to setup a docker service (via terraform) which will run jenkins as containers. I want to bind the host VM's docker docket to the docker service. I tried two options.
While the service gets instantiated successfully, the container doesn't recognize the docker socket. I can see the /var/run/docker.sock
file inside the container but docker command wont work.
The code block for your reference.
DOCKER SERVICE COMMAND
docker service create --name aws --mount=type=bind,src=/var/run/docker.sock,dst=/var/run/docker.sock jenkins/jenkins:lts
TERRAFORM MAIN TF FILE
resource "docker_service" "jenkins_service" {
name = var.project_name
task_spec {
container_spec {
image = docker_image.jenkins_image.name
mounts {
source = var.jenkins_volume
target = "/var/jenkins_home"
type = "bind"
}
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"
}
}
}
Error Message
bash-4.2$ docker exec -u 0 -it 9bc2a468174a bash
root@9bc2a468174a:/# docker
bash: docker: command not found
root@9bc2a468174a:/# ls -ltr /var/run/docker.sock
srwxrwxrwx. 1 root 167 0 Sep 24 11:02 /var/run/docker.sock
Docker Version
-bash-4.2$ docker version
Client:
Version: 18.09.8
API version: 1.39
Go version: go1.10.8
Git commit: 0dd43dd87f
Built: Wed Jul 17 17:40:31 2019
OS/Arch: linux/amd64
Experimental: falseServer: Docker Engine - Community
Engine:
Version: 18.09.8 API version: 1.39 (minimum version 1.12)
Go version: go1.10.8
Git commit: 0dd43dd
Built: Wed Jul 17 17:10:42 2019
OS/Arch: linux/amd64
Experimental: false
Any inputs will be much appreciated.
Regards Senthil Nathan M
bash: docker: command not found
.
You don't have docker client installed in your container. Mounting /var/run/docker.sock
from host inside the container just makes the container's docker client talk to host's docker daemon. You still need to install at least the docker client in your container.