Here is a step-by-step guide on how to use Docker with Jenkins:
Step 1: Install Docker
Firstly, install Docker on your system. The installation process may vary based on the operating system you are using. For detailed installation instructions, check the official Docker documentation.
Step 2: Install Jenkins
Next, install Jenkins on your system. Jenkins can run on various operating systems like Windows, Mac OS, and UNIX.
Step 3: Connect Jenkins to Docker
After both Docker and Jenkins have been installed, you need to connect Jenkins to Docker. For this, go to the Jenkins dashboard. Click on “Manage Jenkins” which you can find on the left side of the dashboard. Now click on “Configure System” and then go down to the “Cloud” section. Here you can configure Docker.
Step 4: Set up a Docker host
Set up a Docker host by clicking the “Docker Host URI” field and entering the URL where Docker host is running.
Step 5: Install Docker Plugin in Jenkins
For running Docker inside Jenkins, you need to a special plugin called the Docker plugin. To install this, go back to your Jenkins dashboard and click on “Manage Jenkins” > “Manage Plugins”. There will be four tabs – Updates, Available, Installed, and Advanced. Go to the “Available” tab and search for “Docker plugin”. Install this plugin.
Step 6: Set up a Jenkins Job
You need to set up a Jenkins job that will pull your Docker image and run that image. To do this, click on “New Item” on your Jenkins dashboard. Enter a title for this job, select “Freestyle project”, and click on OK. Then you’ll need to configure your repository and build triggers.
In the “Build” section, click on “Add build step” and select “Execute shell”. In the command input area, write the necessary Docker command to pull your image from Docker Hub and then run it like “docker pull your_docker_image” and “docker run your_docker_image”.
Click on “Apply” and then “Save”.
Step 7: Build the Job
Now, you can proceed to build the job. After setting everything up, click on the “Build Now” option. Jenkins will start building the job and upon completion, you will see the build status as a color-coded ball on the dashboard.
Remember, providing sufficient permissions to Jenkins and Docker, and creating an appropriate Dockerfile is necessary for building your Docker images.