docker-inbound-agent icon indicating copy to clipboard operation
docker-inbound-agent copied to clipboard

Handling the setting /var/run/docker.sock container mount point

Open citizenkahn opened this issue 5 years ago • 0 comments

How do you handle the situation where I want my jenkins container to be capable of running docker on the ecs. for example this case:

node('aws-ecs-node') {
    def dockerRegistry="https://myregistry.me.com/"
    def dockerRegistryCredId="artifactoryjenkins"
    def dockerImage="myimage:latest"
    
    println "on jenkins node"
    sh "id"
    sh "ls -l /var/run/docker.sock"
    docker.withRegistry(dockerRegistry, dockerRegistryCredId) {
		docker.image(dockerImage).inside('-u root') {
            println "in ${dockerImage}"
            sh "id"
            sh "ls -l /var/run/docker.sock"
		}
    }
    
}

If when I build the image linked to aws-ecs-node I hard code the docker GID from the EC2 instances serving the ECS cluster is all works.

However, when I upgrade ECS docker GID can change leading to lack of access to docker.sock.

It seems from reading other issues etc that pushing the detection of GID, group creation and adding jenkins to that group could be done within the jenkins start up script

Pseudo code:

  1. if /var/run/docker.sock exists and it has a gid
  2. if that gid doesn't exist create as docker group
  3. if docker group exists as another gid - fail
  4. add jenkins user to that group

Or we could create a random hash name for group and always add

citizenkahn avatar Jul 31 '19 15:07 citizenkahn