How to get IP address of docker container in jenkins? How to get IP address of docker container in jenkins? jenkins jenkins

How to get IP address of docker container in jenkins?


Use docker inspect command.

$ sudo docker inspect -f '{{ .NetworkSettings.IPAddress }}' containerID

This command can be run as execute shell command from jenkins.


For getting IP from jenkins for a running container there is two ways.1. if your job is running in master you can use docker-build-step plugin. in this case jenkins will use docker engine of master machine only.

  1. if docker is running on slave machine and job is restricted to that slave machine. we need to use execute shell in jenkins and run following command

    docker inspect $(docker ps |grep {{image id}}|cut -d ' ' -f 1)|grep IPAddress|cut -d '"' -f 4

this will give ip for the container running with that specific image id.If there is more than one container running with same image id, it will generate ip from latest container.