docker-inbound-agent
docker-inbound-agent copied to clipboard
Handling the setting /var/run/docker.sock container mount point
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:
- if /var/run/docker.sock exists and it has a gid
- if that gid doesn't exist create as docker group
- if docker group exists as another gid - fail
- add jenkins user to that group
Or we could create a random hash name for group and always add