Skip to content
This repository has been archived by the owner on Dec 11, 2020. It is now read-only.

Unable to bind Docker running on VM to the container I am running #235

Open
senthilmnathan opened this issue Jan 7, 2020 · 0 comments
Open

Comments

@senthilmnathan
Copy link

senthilmnathan commented Jan 7, 2020

Hi All,

I am running a bunch of jenkins instances as docker services (hosted on 3 node Docker Swarm). I am using terraform to manage the configuration and state.
While everything is working fine, docker.sock wont bind from host to the container.

Terraform Version

Terraform v0.12.8

  • provider.docker v2.4.0

Affected Resource(s)

Custom Jenkins Docker Container is unable to bind with the host instance's docker service.

Terraform Configuration Files

main.tf

#This is the main script used by the project

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"
    }
  }
}

Expected Behavior

I should be able to run docker commands on the containers

Actual Behavior

I am unable to run docker command from within the docker container

-bash-4.2$ docker exec  -u 0 -it f1f1f38e9316 bash
root@f1f1f38e9316:/# su - jenkins
jenkins@f1f1f38e9316:~$ docker
-su: docker: command not found
jenkins@f1f1f38e9316:~$

Steps to Reproduce

Please list the steps required to reproduce the issue, for example:

  1. terraform apply
  2. docker exec -u 0 -it <container_id> bash
  3. docker
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants