Maven Installation on Ubuntu Linux

Launch a Ubuntu Virtual Machine in AWS Cloud

Connect through Putty

login with ubuntu user

$ cd /opt

$ wget https://download.java.net/java/GA/jdk13.0.1/cec27d702aa74d5a8630c65ae61e4305/9/GPL/openjdk-13.0.1_linux-x64_bin.tar.gz

$ tar -xvf openjdk-13.0.1_linux-x64_bin.tar.gz

$ cd  (enter)

$ vi .profile

JAVA_HOME=’/opt/jdk-13.0.1′

PATH=”$JAVA_HOME/bin:$PATH”

export PATH

$ source ./profile

$ java -version

openjdk version “13.0.1” 2019-10-15

OpenJDK Runtime Environment (build 13.0.1+9)

OpenJDK 64-Bit Server VM (build 13.0.1+9, mixed mode, sharing)

$ cd  /opt

$ wget https://dlcdn.apache.org/maven/maven-3/3.9.10/binaries/apache-maven-3.9.10-bin.tar.gz

$ tar -xzvf apache-maven-3.9.10-bin.tar.gz

$ cd (enter)

$ vi .profile

M2_HOME=’/opt/apache-maven-3.9.10′

PATH=”$M2_HOME/bin:$PATH”

export PATH

$ source .profile

$ mvn -version

Apache Maven 3.9.10 (cecedd343002696d0abb50b32b541b8a6ba2883f)

Maven home: /opt/apache-maven-3.9.10

Java version: 13.0.1, vendor: Oracle Corporation, runtime: /opt/jdk-13.0.1

Default locale: en, platform encoding: UTF-8

OS name: “linux”, version: “4.15.0-47-generic”, arch: “amd64”, family: “unix”

$

Install git software

$ apt  install git -y

$ git clone https://github.com/wst-devteam/maven-web-application.git

$ cd maven-web-application

$ ls

To Convert the source code into package war file

$ mvn clean install

$ ls  target –> to see the war file

Docker Setup on Ubuntu Linux

1st Method

$ sudo apt-get update

$ sudo apt-get install ca-certificates curl

$ sudo install -m 0755 -d /etc/apt/keyrings

$ sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc

$ sudo chmod a+r /etc/apt/keyrings/docker.asc

$ echo \

  “deb [arch=$(dpkg –print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \

  $(. /etc/os-release && echo “${UBUNTU_CODENAME:-$VERSION_CODENAME}”) stable” | \

sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

$ sudo apt-get update

Install the Docker Packages

$ sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

$ sudo docker run hello-world

2nd Method to install the docker

$ curl  -fsSL get.docker.com | /bin/bash

3rd  Method to install the docker

$ apt install docker.io -y

To check the docker is installed or not

$ sudo docker version

To avoid running the sudo command

$  sudo usermod -aG ubuntu $USER

$  sudo usermod -aG ubuntu $USER

Update the kernel

$ newgrp docker

$ docker version

===========================The End================================

Docker Setup on Redhat LInux on Laptop VM

Login as root user

Create a user called centos

# useradd centos

Create the password

# passwd centos

Convert the local user as a sudo user

# visudo

root    ALL=(ALL)       ALL –> This line is default

centos  ALL=(ALL)       NOPASSWD: ALL –> Add this line

Save the file(wq!)

Logoff from root account and login with user centos

$ sudo dnf update

$ sudo dnf install java-11-openjdk-devel

$  java -version

$  cd /opt

$ sudo wget https://dlcdn.apache.org/maven/maven-3/3.9.10/binaries/apache-maven-3.9.10-bin.tar.gz

$ sudo tar xzvf apache-maven-3.9.10-bin.tar.gz

$ sudo vi /etc/profile.d/maven.sh

export M2_HOME=/opt/apache-maven-3.9.10

export PATH=${M2_HOME}/bin:${PATH}

$  sudo chmod +x /etc/profile.d/maven.sh

$ source /etc/profile.d/maven.sh

$ mvn  -version

Docker commands

To check the docker is installed or not

$ docker info

To check the docker version

$ docker -v

$ docker version

To see the docker images

$ docker images

$ docker image ls

To check the docker service is running or not

$ service docker status

$ git clone https://github.com/wst-devteam/maven-web-application.git

$ cd maven-web-application

$ ls

To Convert the source code into package war file

$ mvn clean install

$ ls  target –> to see the war fileTo create the docker image

To create the docker image

build$ cd maven-web-application

build$ docker build -t learntechmasters/maven-web-application:1    .

build$ docker images

To see the layers in the docker file

build$ docker history learntechmasters/maven-web-application:1

To authenticate with remote respository hub,.docker.com

build$ docker login -u <username>

To push the Docker image to the remote repository

build$ docker push learntechmasters/maven-web-application:1

To remove the docker images

build$ docker rmi <image ID>

Launch another Linux Instance or VM

Set up this server as Deployment Server

Install the docker

deployment$ sudo curl -fsSL get.docker.com | /bin/bash

deployment$ docker create   –name mavenwebapp   -p  8080:8080 learntechmasters/maven-web-application:1

To see the containers which are created

deployment$ docker ps -a

deployment$ docker container ls  -a

To start the container

deployment$ docker start mavenwebapp

deployment$ docker container  ls

deployment$ docker  ps

To remove the container

deployment$ docker stop mavenwebapp

deployment$ docker  rm mavenwebapp

To remove the container without stopping the container

deployment$ docker rm -f mavenwebapp

To create the container and start the container

deployment$ docker run -d –name mavenwebapp   -p  8080:8080 learntechmasters/maven-web-application:1

deployment$ docker ps

To check the ports which are being used

deployment$ sudo apt install net-tools  -y

deployment$ sudo netstat -tunlp

How to see the container details

deployment$ docker inspect <containerName> or ID

To test the container is running or not

deployment$ curl  -v  172.17.0.2:8080 –> To see the tomcat home page

deployment$ curl  -v  172.17.0.2:8080/maven-web-application/ –> To see the maven application

Go to Build Server

To create Java Application as a Container

build$ git clone https://github.com/wst-devteam/java-web-application.git

build$ cd  java-web-docker

Create the war file

build$ mvn clean install

build$ ls  target

Create the docker image

build$ docker build -t learntechmasters/java-web-app:1  .

build$ docker images

build$ docker  push  learntechmasters/java-web-app:1  . 

Goto Deloyment Server

deployment$ docker run – -name  javawebapp   -p   9090:8080  learntechmasters/java-web-app:1

deployment$ docker ps

deployment$ docker  ps  -a

deployment$ docker inspect  javawebapp

deployment$ docker inspect javawebapp | grep Port

To see the IP address of the Container

deployment$ docker inspect javawebapp | grep IPAddress

To access our application

deployment$ curl  -v 172.17.0.2:8080/java-web-app/

To access our application

deployment$ curl  -v 172.17.0.2:8080/java-web-app/

 You can see the java application from the web browser

If your company using nexus with domain cts.com

docker build  -t  nexus.cts.com/maven-web-application:1   .

docker push  nexus.cts.com/maven-web-application:1   .

You can also use nexus server IP with port number

docker build  -t  172.31.23.7:8083/maven-web-application:1   

docker push -t  172.31.23.7:8083/maven-web-application:1   

If the company using ECR

docker build  -t  13905806863.dkr.ecr.ap-south-1.amazonaws.com/maven-web-application:1     .

docker  push -t  139058068863.dkr.ecr.ap-south-1.amazonaws.com/maven-web-application:1     .

For authentication to nexus server

docker login  -u  admin  -p  admin123  nexus.cts.com

docker login  -u  admin  -p  admin123  172.21.0.2:8083

For authentication to ECR

docker  login  -u  AWS  -p <password> 139058068863.dkr.ecr.ap-south-1.amazonaws.com

To pull the docker images

docker  pull  learntechmasters/maven-web-application:1

If your company using nexus with domain cts.com

docker build  -t  nexus.cts.com/maven-web-application:1   .

docker push  nexus.cts.com/maven-web-application:1   .

You can also use nexus server IP with port number

docker build  -t  172.31.23.7:8083/maven-web-application:1   

docker push -t  172.31.23.7:8083/maven-web-application:1   

If the company using ECR

docker build  -t  139058068863.dkr.ecr.ap-south-1.amazonaws.com/maven-web-application:1     .

docker  push -t  139058068863.dkr.ecr.ap-south-1.amazonaws.com/maven-web-application:1     .

For authentication to nexus server

docker login  -u  admin  -p  admin123  nexus.cts.com

docker login  -u  admin  -p  admin123  172.21.0.2:8083

For authentication to ECR

docker  login  -u  AWS  -p <password> 139058068863.dkr.ecr.ap-south-1.amazonaws.com

To pull the docker images

docker  pull  learntechmasters/maven-web-application:1

docker pull nexus.ibm.com/maven-web-application:1

docker pull 139058068863.dkr.ecr.ap-south-1.amazonaws.com

Dangling Images

Image without any repository reference or tag called a Dangling Images

To see only dangling images

build$ docker images -f dangling=true

How to create the tag to dangling images

build$ docker tag <imageID> <RegistryName>/RepositoryName>

build$ docker tag 977o474b1bb0  learntechmasters/maven-web-application:1

To delete the multiple docker images in one command

build$ docker  rmi  -f  $(docker  images  -q)

To see only  the Image ID’s

build$ docker  images  -q

To copy the docker images from one host to another host

build$ docker save <image tag> -o <filename.tar>

build$ docker  save learntechmasters/maven-web-application  -o  mavenwebimage.tar

build$ ls

If it is  Laptop

build$ scp  mavenwebimage.tar  ubuntu@172.31.9.174:/home/ubuntu

If it is AWS Cloud

build$ vi  devops.pem

Copy and paste the key

build$ chmod 400 devops.pem

build$ scp   -i  devops.pem mavenwebimage.tar  ubuntu@172.31.9.174:/home/ubuntu

Goto deployment server

docker load  -i <filename.tag>

Deployment$ docker load  -i  mavenwebimage.tar

To clean up your docker run docker system prune

$ docker system prune

To remove only dangling images

$ docker image prune

To remove all stopped containers

$ docker container prune

To remove all networks

$ docker network prune

To remove all volumes

$ docker volume prune

To create nginx as a container

deployment$ docker run  -d  –name nginxcontainer  -p  80:80  nginx:stable

deployment$ docker  ps

To see the nginx home page

deployment$ curl  localhost:80

To rename the container

docker  rename  <old name>  <new name>

To pause the application

$ docker  pause  mavenwebapp

To unpause the application

$ docker unpause  mavenwebapp

To see only exited containers

$ docker  ps  -aq  -f  status=exited

To remove exited containers

$ docker rm $(docker  ps -aq -f status=exited}

To delete all the containers which are running and which are exited

$ docker  rm  -f  $(docker  ps -aq)

$ docker  ps  -a

 To see what process is running inside these containers

$ docker top nginxcontainer

To see the list of files available in container

$ docker exec mavenwebapp  ls

$ docker exec mavenwebapp ls webapps

To go to inside the container shell

$ docker exec  -it mavenwebapp bash

bash-4.2# java  -version

bash-4.2#  ps  -ef

To see all the container logs

$ docker  logs  mavenwebapp

To allocate the resources like memory and processor while creating the container

docker  run  -d  –name <containerName> -p <hostPort:containerPort> –cpus 500M  –memory 256M <image>

$ docker  run  -d  –name javawebapp  -p  9090:8080 –memory 250M  learntechmasters/java-web-application:1

$ docker  ps  -a

$ docker   inspect  javawebapp

To see the Memory and CPU utilization of the container

$ docker stats  javawebapp

To see the files inside the container

$ docker  exec  javawebapp  ls

$ docker  exec  javawebapp  ls  logs

To copy files from container to host machine

$ docker  cp  javawebapp:/usr/local/tomcat/logs/catalina.2025-06-24.log  catalinalogs.log

To check the default home directory of your application

$ docker exec javawebapp  pwd

To copy files from host machine to container

$ docker  cp  text.txt  javawebapp:/usr/local/tomcat/test.txt

ADD Instruction

Add instruction to download the software and copy to /opt

add  https://dlcdn.apache.org/maven/maven-3/3.9.10/binaries/apache-maven-3.9.10-bin.tar.gz  /opt

Download the software to the current directory

add  https://dlcdn.apache.org/maven/maven-3/3.9.10/binaries/apache-maven-3.9.10-bin.tar.gz    .

RUN Instruction

RUN instruction to run the command while building the image

RUN  mkdir  /opt/test

RUN apt update  -y

RUN apt  install curl wget  git  -y

RUN wget https://dlcdn.apache.org/maven/maven-3/3.9.10/binaries/apache-maven-3.9.10-bin.tar.gz

CMD Instruction

Using CMD we can run the commands or scripts while starting the container

CMD [“catalina.sh”,”run”]

To create the docker image without build cache

$ docker build – -no-cache  -t  imageone:1

To create the container interactively

$ docker  run -it imageone:1  bash

# git  – -version

ENTRYPOINT

Using ENTRYPOINT we can run or execute the commands while starting the container

ENTRYPOINT [“sh”.”catalina.sh”]

WORKDIR

The WORKDIR instruction create the directory automatically while building the image

ENV

We can set the environment variables for images and containers using this ENV in a dockerfile

these environment variables are available in image and container as well

To see the environment variables inside the container

$ docker run imageone:1 env

ARG

It’s like kind of a variables

You can pass the argument while building the image

The user can pass the variable value at build time

ARG baseImageTag

FROM centos:$baseImageTag

USER

Which user my container should start or which user command should be execute in the image

Which user the process should be start, you can use USER instruction

To create jenkins as a container

$ docker  run  -d  –name  jenkinscontainer  -p 6060:8080  jenkins/jenkins:lts

To see the Jenkins password

$ docker  exec  jenkinscontainer  cat  /var/jenkins_home/secrets/initialAdminPassword

In Jenkins Docker file 

ARG user=jenkins

ARG group=jenkins

 To start the container automatically when host is rebooted

docker  run  -d  – -name <containerName>  -p <hostPort:containerPort>  – -restart always <imageTag>

To see the docker networks

$ docker network ls

To know in which network the container is created

$ docker inspect javawebapp

To see the subnet range of docker network

$ docker network inspect bridge

To create our own docker network

docker network create -d <driver> <networkName>

$ docker network create -d bridge amazonbridge