Deploy a Spring boot web application to docker using the Jenkins pipeline.
- Environment used is Ubuntu18 in cloud9.
- Jenkins with Blue Ocean Plugin & Pipeline-AWS Plugin.
- AWS account with IAM role created.
- Unix -
./mvnw - Windows -
./mvnw.cmd
- Ubuntu -
sudo apt-get install maven -y - Windows - Documentation by https://maven.apache.org/
Install Jenkins on Ubuntu: or Refer Documentation for others
wget -q -O - https://pkg.jenkins.io/debian-stable/jenkins.io.key | sudo apt-key add -sudo sh -c 'echo deb https://pkg.jenkins.io/debian-stable binary/ >> /etc/apt/sources.list'sudo apt-get updatesudo apt-get install jenkinssudo systemctl start jenkinssudo systemctl enable jenkinssudo systemctl status jenkins
- In Jenkins, Click "Open Blue Ocean" and click "New Pipeline".
- Select GitHub from the options available, a token needs to be generated. A link to https://github.com/settings/tokens/new?scopes=repo,read:user,user:email,write:repo_hook needs to be clicked to generate a token for Jenkins to use and Make sure you copy the token and save it.
- After pasting the token into the form in Jenkins, click "connect", and your account should show up.
- Next, select the repo that was created, and click "create pipeline."
- In the page where the job shows, there is a gear icon - click on it to edit the job directly. Find the "Scan repository triggers" and click on "Periodically if not otherwise run," and select an interval of 2 minutes.
Like this - Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock
- Add the docker group if it doesn't already exist:
sudo groupadd docker - Add the user "jenkins" to the docker group:
sudo usermod -a -G docker jenkins - Then restart Jenkins:
sudo service jenkins restart
- mvn build -
mvn clean install package - Docker image build -
docker build -t travelblog . - Remove any running Container -
./stop-container.sh - Run Docker Container -
docker container run --name tbcontainer -p 8000:8080 -d travelblog
- Unix -
./mvnw spring-boot:run - Windows -
./mvnw.cmd spring-boot:run
- Paste the IP and append “/travelblog” on the end in the browser.