How to get Image ID of docker in jenkins?
One liner based on docker documentation:
sudo docker images --filter=reference=image_name --format "{{.ID}}"
Replace image_name
by your actual docker image name.You can store that value in a shell variable for further referencing with:
IMAGE_ID=$(sudo docker images --filter=reference=image_name --format "{{.ID}}")
And then access it with $IMAGE_ID
A simpler way to solve it:
docker images --filter="reference=your_image_name" --quiet
What this command means:
- --filter : Search a image based on name (represented by your_image_name)
- --quiet : Return only the image ID
Reference: https://docs.docker.com/engine/reference/commandline/images/
You can see the docker image id (for the images you have built or pulled from docker hub) using the following command: docker images
Update after comments from OP:
docker images --filter
only implements dangling=true so you can't search for container ids using this way. so you'll have to rely on shell scripting, here's an example:
docker images | grep -E '^golang.*latest' | awk -e '{print $3}'
You'll need to tailor the regex in the grep to match your image name and tag.