0

I want my docker to run in this way

docker run -d -it --privileged <docker_img_name> /usr/sbin/init 456547fa74aa4b302d8b6f5679a6a079caf0e123654ecd5cda7b3587aa9e225d

docker exec -it 456547fa7 bash

pipeline {
  agent {
        kubernetes {
            label "Docker"
            inheritFrom 'rootless' 
            defaultContainer 'dind'
            yaml container([[ name: 'buildimg', image: "<docker_image_name>"]])
        }
  }
    options {
        timeout(time: 180, unit: 'MINUTES')
        buildDiscarder(logRotator(daysToKeepStr: '30', artifactDaysToKeepStr: '30'))
        timestamps()
    }
    environment {
        
        IMG_SRC="somesrc.com"
        IMG_NAME="someimg.qcow2"
        
    }
    
    stages{
            stage('Fetch_image_list') {
                    steps {
                        container('buildimg') {
                           
                    sh'''


echo "INFO : Some Stages"

'''
                }
            }
        }
        
    
}

How to run Jenkins with Docker on Kubernetes? Referred to this but still didn't get it. Sorry I'm too new to Jenkins, Docker & Kubernetes in general. I'm in my second month of internship... Please help.

  • Why do you want to run those specific commands? That sort of looks like you're trying to explicitly make a container run systemd, with unrestricted access to control the host, and then get a debugging shell inside it; neither task is something you'd typically do in a CI pipeline and I'd hope both are a little unusual. – David Maze Feb 24 '23 at 11:23
  • (I'd start with the standard Jenkins support described in [Using Docker with Pipeline](https://www.jenkins.io/doc/book/pipeline/docker/), and adapt Docker features into that model where it's incomplete.) – David Maze Feb 24 '23 at 11:25
  • @DavidMaze I keep getting this error "Failed to get D-Bus connection: Operation not permitted" for which I tried the solution mentioned [link](https://stackoverflow.com/questions/50393525/failed-to-get-d-bus-connection-operation-not-permitted): `docker run -d -it --privileged /usr/sbin/init` `docker exec -it 456547fa7 bash` And running it like this doesn't give me that error – Sharon John D'Souza Feb 24 '23 at 12:08
  • That question uses the text "run a service in a Docker image", which doesn't make sense; a container is a wrapper around a single process, not a full-blown OS with system daemons. It's mostly accurate to say that commands like `systemctl` or `service` just don't work at all in Docker and you need a different way to launch the program (usually as a foreground process in the image's `CMD`). – David Maze Feb 24 '23 at 15:03

0 Answers0