2 years ago

#19363

test-img

Erred Occuror

Cannot execute docker inspect inside Jenkins job

I need to execute docker inspect from a Jenkins pipeline to get the health status of a container. I tried the following in my pipeline script:

def containerHealth = sh(
    script: "docker inspect --format='{{json .State.Health.Status}}' db",
    returnStdout: true
).trim()

In my docker-compose file I mounted docker.sock as the following:

jenkins:
    container_name: jenkins-master
    ports:
        - '8080:8080'
        - '50000:50000'
    image: jenkins-master
    restart: always
    volumes:
        - /var/run/docker.sock:/var/run/docker.sock

However it doesn't work and I get this output message: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running? But I can execute docker --version from the pipeline properly.

Does anyone have an idea how can I get through this?

docker

jenkins

docker-compose

jenkins-pipeline

docker-command

0 Answers

Your Answer

Accepted video resources