I need to run docker container through Jenkins. For that I used "Start/Stop Docker Containers" as build step
Start/Stop Docker Containers
Action to choose : Run container
Docker Cloud name : docker_demo
ID : DOCKER_IMAGE_ID
DNS
Port bindings :port
Bind all declared ports :
Hostname : ip address
While running the job,it is telling that "Invalid ID". Can anyone suggest,How to get Image ID of docker in jenkins??
This Dockerfile is built from Jenkins official image, install docker and give access to user jenkins build dockers. To get the jenkins docker build, let's run the following command: $ docker build -t jenkins-with-docker .
You can see the docker image id (for the images you have built or pulled from docker hub) using the following command: docker images 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:
Using the withRun method, implemented in the Docker Pipeline plugin’s support for Scripted Pipeline, a Jenkinsfile can run MySQL as a sidecar: This example can be taken further, utilizing two containers simultaneously. One "sidecar" running MySQL, and another providing the execution environment, by using the Docker container links.
To build the image on your own computer, navigate to the project directory (the one with your application code and the Dockerfile), and run docker build: docker build . -t getintodevops-hellonode:1 This instructs Docker to build the Dockerfile in the current directory with the tag getintodevops-hellonode:1.
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:
Reference: https://docs.docker.com/engine/reference/commandline/images/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With