does not seem to be running inside a container

Article ID:360033981612
2 minute readKnowledge base

Issue

When using withDockerContainer inside a Pipeline and running the job, I can see the following message in the build logs:

AGENT_NAME does not seem to be running inside a container

Short Explanation

AGENT_NAME does not seem to be running inside a container: This is a simple logging improvement and it is informational. This log line has been added in Docker Pipeline Plugin version 1.11 to improve diagnostics.

The docker pipeline plugin checks if the current agent AGENT_NAME is or is not running inside a docker container when invoking the inside step. The plugin needs that information to know which volumes need to be mounted to the new container when launching withDockerContainer or similar.

Longer Explanation with Examples

Here is a rough example of both scenarios with non-declarative pipeline:

Agent not running inside a container:

node ('non-docker-agent') {

    docker.withServer($DOCKER_SERVER) {

        // Right here we are currently in `non-docker-agent` and Jenkins check if `non-docker-agent` itself runs inside a container
        // It is not, Jenkins says "'non-docker-agent' does not seem to be running inside a container"
        docker.image('$DOCKER_IMAGE').inside {
            sh "hostname"
        }

    }
}

Agent that is running inside a docker container, id 'xxxxxx':

node ('docker-agent') {

    docker.withServer('$DOCKER_SERVER') {

        // Right here we are currently in `docker-agent` and Jenkins check if `docker-agent` itself runs inside a container
        // It is. Jenkins says "'docker-agent'  seems to be running inside container 'xxxxxx'"
        docker.image('$DOCKER_IMAGE').inside {
            sh "hostname"
        }

    }
}

If the agent is already running inside a container, the container created by withContainerStep will "inherit" its volumes if required.

The plugin is designed so that you can transparently work with the workspace from the host machine in a similar environment just inside the container. As an alternative, remember that you can always fall back to calling docker CLI directly from a Pipeline sh step instead of using withDockerContainer or similar Docker Pipeline steps implemented by the Docker Pipeline plugin or any others.

Tested product/plugin versions