Docker as we know, is an open platform for developers and sysadmins to build, ship, and run distributed applications, whether on laptops, data center VMs, or the cloud.
Today we are going to check how to configure Jenkins to build Docker Images based on a Dockerfile. Below are the steps of how you can use Docker within a CI/CD pipeline, using Images as a build artifact that can be promoted to different environments and finally production.
This quickstart assumes basic understanding of Docker concepts, please refer to earlier posts for understanding on Docker & how to install and containerize applications.
Quick Snapshot
Currently, I have Jenkins running on Docker container, if you do docker ps
command it would show you the status of the container.
Launch Jenkins’ dashboard
Our 1st step is to configure the Docker plugin. Whenever a Jenkins build requires Docker, it will create a “Cloud Agent” via the plugin. The agent will be a Docker Container configured to talk to our Docker Daemon. The Jenkins build job will use this container to execute the build and create the image before being stopped.
The Docker image will be stored on the configured Docker Daemon. The Image can then be pushed to a Docker Registry ready for deployment.
Once the Docker & GIT plugins have been installed, now we can go ahead and configure how they launch the Docker Containers.
The configuration would be used by the plugin which Docker Image to use the agent and which Docker daemon to run the containers and builds on. The plugin treats Docker as a cloud provider, spinning up containers as and when the build requires them.
Now plugin can communicate with Docker, the next step would be to configure how to launch the Docker Image for the agent.
jenkins
and the password is jenkins
.To test the setup, create a new job to
Build step :
ls docker info docker build -t jenkins-demo:${BUILD_NUMBER} . docker tag jenkins-demo:${BUILD_NUMBER} jenkins-demo:latest docker images
The first command lists all the files in the directory which will be built. When calling docker build we use the Jenkins build number as the image tag. This allows us to version our Docker Images. We also tag the build with latest.
Docker File:
FROM scratch EXPOSE 80 COPY http-server / CMD ["/http-server"]
On the left-hand side, select Build Now. You should see a build scheduled with a message “(pending—Waiting for next available executor)”.
Jenkins is launching the container and connecting to it via SSH. Sometimes this can take a moment or two.
You can see the progress using
docker logs --tail=10 jenkins
Once the build has completed you should see the Image and Tags using the Docker CLI
docker images
Like this post? Don’t forget to share it!
Writing software backed by artificial intelligence can create everything from emails to blog articles. AI…
In today's interconnected digital realm, cybersecurity stands as a paramount concern for organizations, irrespective of…
The cryptocurrency market is famed for its volatility, presenting each opportunity and demanding situations for…
Games since time immemorial have been winning at captivating the users and teleporting them onto…
We are living within an innovation curve wherein cutting-edge technologies are making a hustle and…
Whether it’s the healthcare industry or the automobile sector, artificial intelligence has left its impact…
This website uses cookies.