DevOps Project: Build and push the image to DockerHub and run the container through Jenkins

DevOps Project: Build and push the image to DockerHub and run the container through Jenkins

·

3 min read

In the fast-paced world of software development, efficiency is key. Developers strive to build, test, and deploy applications swiftly and reliably. This is where the powerful combination of Docker and Jenkins comes into play. Docker enables containerization, providing a consistent and isolated environment for applications to run, while Jenkins automates the entire software development lifecycle.

In this blog, we will delve into the integration of Docker and Jenkins to create a seamless development workflow that fosters collaboration, improves efficiency, and ensures the delivery of high-quality software.

Follow the below steps to install Jenkins on GCP VM(Linux)

  1. create a new VM, add a firewall rule to allow port 8080(for Jenkins), and click on SSH to connect to VM.

Type this on Terminal:

sudo apt update
sudo apt install -y openjdk-11-jdk
java –version

wget https://pkg.jenkins.io/debian-stable/binary/jenkins_2.332.3_all.deb
sudo dpkg -i jenkins_2.332.3_all.deb

sudo apt-get update
sudo apt-get install jenkins
sudo systemctl start Jenkins
sudo service jenkins start

Jenkins runs on port 8080 by default. Open a web browser and navigate to http://<your-vm-ip>:8080 access the Jenkins web interface.

For getting the password, run this :

sudo cat /var/lib/jenkins/secrets/initialAdminPassword

INSTALL DOCKER

  1. sudo apt update

    sudo apt install docker.io

    sudo systemctl start docker

    sudo usermod -aG docker dockeruser

    docker version

  2. open below file

    sudo visudo -f /etc/sudoers.d/dockeruser

    Add this to file: dockeruser ALL=(ALL) NOPASSWD: ALL

  3. Add the Dockerfile to the git hub.

    Start with Jenkins:

    1. Install Plugins - Docker, docker step, cloudbees docker.

    2. Add global credential for docker hub in Jenkins.

      1. Login Docker hub from VM: cmd- docker login

      2. Create a job in Jenkins - Pull the PHP website, and the Dockerfile from the git repo and build and push image to docker hub

      3. Add git repository

      4. In the Build step, select Docker Build and Publish

      5. Provide the repository of dockerhub: Repository Name formate - username/repo

      6. Add the credential which was added to the global credential

      7. To run the container, Add the next build step and add execute the shell command and add these commands.

        Save the configuration and run the build.

      8. Check in the console output

        Docker Hub:

        Note: Everything is figurable, you will get lots of issues while building a project and you can use various resources to solve them. Issue>google>solve>Iterate.

        Conclusion:

        In conclusion, the seamless integration of these tools empowers developers to focus on crafting exceptional code, while automation takes care of the tedious and repetitive tasks. By containerizing applications with Docker, we ensure consistency across various environments, making deployment a breeze.

        Jenkins' robust automation capabilities enable us to easily implement continuous integration and continuous delivery. This, in turn, fosters a culture of collaboration and rapid feedback, where engineers can confidently deliver changes to production without fear of breaking existing features. Embrace this transformative duo, and witness firsthand wonders. Happy Learning!