Here is a quick and full example to build a docker image from private GitHub repo and push to docker hub with declarative pipeline in Jenkins.
I created a sample repo with basic Dockerfile and Jenkinsfile
$ cat Dockerfile
FROM ubuntu:20.04
RUN apt update && apt upgrade -y
Configure Jenkins
Ensure that you installed docker engine on Jenkins instance and git, docker plugins
Install Docker-CE on Ubuntu 18 from https://docs.docker.com/engine/install/ubuntu/
After that, allow Jenkins users to access the docker socket.
sudo usermod -aG docker jenkins
sudo systemctl restart jenkins
Test your docker access with Jenkins user
$ sudo su - jenkins
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
Create credentials on Jenkins for GitHub and docker hub
To create a GitHub credentials we need to create a token. Check the following URL to create a personal API Token
To create a GitHub credentials go to Manage Jenkins->Manage Credentials(Under Security)
click to Jenkins Store
#pipeline #docker #github #jenkins