Thursday, 29 July 2021
PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
The above Error states that the server you are accessing has some certificate, and you did not have it in your machine. You have to import this local, in the case of docker follow the below steps.
This post Assumes that you have valid certificates with you before proceeding.
Starting Docker Images with PKI certificates
Happy Learning !!!!
Starting Docker Images with PKI certificates
Before starting this post, Make Sure you copy the certificate to the location where you have the docker file. Edit the following docker file according to your requirement. My Requirement was to copy the jar and start in docker.
Below is my DockerFile
FROM java:8
EXPOSE 8084
ADD ./target/my.jar my_docker.jar
USER root
COPY my.cer $JAVA_HOME/jre/lib/security
RUN \
cd $JAVA_HOME/jre/lib/security \
&& keytool -keystore cacerts -storepass changeit -noprompt -trustcacerts -importcert -alias ldapcert -file my.cer
ENTRYPOINT ["java","-jar","my.jar"]
Once you copy the certificate and import it using the key tool it will import successfully.
After this build it and run using the port.
Building the Docker image
docker build -t cert-sample .
Running the Docker image
docker run -d -p 8084:8084 cert-sample
Happy Learning!!!!
Sunday, 18 July 2021
Kubernetes read local docker images
Follow the below steps to read the docker images from local instead of pulling them every time from the docker hub. By default, it always reads the images from the docker hub.
This saves us a lot of time by reducing the time to push to the docker hub. It takes a lot of time to push the image from local and tags it.
There are two steps involved.
Step:1
Open the command prompt in admin mode and execute the below command.
C:\Users\Syed>minikube docker-env
Once you execute the command "minikube docker-env" you will see the following output.
SET DOCKER_TLS_VERIFY=1
SET DOCKER_HOST=tcp://127.0.0.1:32770
SET DOCKER_CERT_PATH=C:\Users\Syed\.minikube\certs
SET MINIKUBE_ACTIVE_DOCKERD=minikube
REM To point your shell to minikube's docker-daemon, run:
REM @FOR /f "tokens=*" %i IN ('minikube -p minikube docker-env') DO @%i
Just Copy the Last line after REM and execute in the same command prompt.
C:\Users\Syed>@FOR /f "tokens=*" %i IN ('minikube -p minikube docker-env') DO @%i
After making this change, the local docker images will be visible to the K8's.
Step:2
In the Yaml file of the K8's make sure that the image pulls policy to be "Never". Point this file to the local docker build name and the tag.
eg: imagePullPolicy: Never
Once you do the above two steps, then from next time make changes to the docker file in local, build it and see the changes in the K8's.
Happy Learning!!!!
Thursday, 17 June 2021
Deploying SpringBoot Struts 2 Integration Project in Docker
Follow my previous post and create the sample spring struts integration project from here.
Create a Docker File: Dockerfile
FROM tomcat:latest
ADD target/SpringStrutsDemo-0.0.1-SNAPSHOT.war /usr/local/tomcat/webapps/
EXPOSE 8080
CMD ["catalina.sh","run"]
Build and tag the Docker File:spring-strutsdemo
C:\Users\Syed\Spring-workspace\SpringStrutsDemo>docker build -t spring-strutsdemo .
Sending build context to Docker daemon 58.75MB
Step 1/4 : FROM tomcat:latest
---> 5505f7218e4d
Step 2/4 : ADD target/SpringStrutsDemo-0.0.1-SNAPSHOT.war /usr/local/tomcat/webapps/
---> a30a842ce761
Step 3/4 : EXPOSE 8080
---> Running in 35d616d2803f
Removing intermediate container 35d616d2803f
---> 2c848691227a
Step 4/4 : CMD ["catalina.sh","run"]
---> Running in 270c9c8d4b5d
Removing intermediate container 270c9c8d4b5d
---> f7b915b47c1f
Successfully built f7b915b47c1f
Successfully tagged spring-strutsdemo:latest
Run the docker image from the tag
docker run -p 8080:8080 spring-strutsdemo
This will start in 8080 port. In case if it is not started well there could be an issue with the java version used in the docker or the project is not properly generated and war is invalid.
Access it using
http://localhost:8080/SpringStrutsDemo-0.0.1-SNAPSHOT/message.action
where SpringStrutsDemo-0.0.1-SNAPSHOT is the context.
Sunday, 1 November 2020
Creating Jenkins pipeline to Build and deploy the Docker Image
To Understand the Jenkins pipeline and trigger build refer to my previous here.
Prerequisite.
Install the Following plugins in Jenkins. navigating to ManageJenkins > ManagPlugins
Navigate to Dashboard and Select Manage Jenkins
Select Stores scoped to Jenkins > Global Credentials > Add Credentials
Make sure you give some Id to the credentials.
Step:4 Create Pipeline.
pipeline {
environment {
registry = "syedghouse14/greet-user-repo"
registryCredential = 'Docker-Hub'
dockerImage = ''
dockerfile="${workspace}\\GreetUser\\Dockerfile"
pomfile="${workspace}\\GreetUser\\pom.xml"
}
agent any
stages {
stage('Cloning Git') {
steps {
git 'https://github.com/Syed-SearchEndeca/gretuser.git'
}
}
stage ('Build') {
steps {
withMaven(maven : 'apache-maven-3.6.3') {
bat "mvn clean package -f ${pomfile}"
}
}
}
stage('Building image') {
steps{
script {
dockerImage = docker.build registry + ":$BUILD_NUMBER",
"--file ${dockerfile} ."
}
}
}
stage('Deploy Image') {
steps{
script {
docker.withRegistry( '', registryCredential ) {
dockerImage.push()
}
}
}
}
stage('Remove Unused docker image') {
steps{
bat "docker rmi $registry:$BUILD_NUMBER"
}
}
}
}
Things to Consider
Make sure you pass the credentials created in the pipeline.
Pass the Docker File explicitly
"--file ${dockerfile} ."
You will encounter the following error and resolution for that.
Step 4/5 : COPY GreetUser-0.0.1-SNAPSHOT.jar app.jar
COPY failed: stat /var/lib/docker/tmp/docker-builder619200988/GreetUser-0.0.1-SNAPSHOT.jar: no such file or directory
In One of the step it fails, For this edit the docker file as below.
Initial Docker file.
FROM openjdk:8-jdk-alpine
ARG JAR_FILE=target/*.jar
COPY ${JAR_FILE} app.jar
ENTRYPOINT ["java","-jar","/app.jar"]
Modified Docker file.
FROM openjdk:8-jdk-alpine
RUN addgroup -S spring && adduser -S spring -G spring
USER spring:spring
ENTRYPOINT ["java","-jar","target/*.jar"]
Here I skipped the Copy Step Instead added the target directly. Hope this helps.
Happy Learning !!!!
Sunday, 30 August 2020
How to Push the Images to Docker Hub
Friday, 12 June 2020
Understanding docker file
Docker can build images automatically by reading the instructions from a Dockerfile. A Dockerfile is a text document that contains all the commands a user could call on the command line to assemble an image. Using docker build users can create an automated build that executes several command-line instructions in succession.
Now
its time to understand about the docker engine and docker daemon.
Docker Engine.
Docker engine or Docker is a client server application that builds and executes containers using Docker components. REST API is a primary mode of communication between Docker Client and Docker Daemon.
Docker Daemon.
Docker Daemon is a
server which interacts with the operating system and performs all kind of
services. The Docker Daemon listens for REST API request and performs the
operation. A command dockerd is used to start a Docker Daemon. Docker Host runs
the Docker Daemon and Registry.
Docker Daemon checks the client request and
communicates with the Docker components in order to perform a service whereas,
Docker Engine or Docker is the base engine installed on your host machine to
build and run containers using Docker components and services.
Environment
variables are supported by the following list of instructions in the Dockerfile
:
The COPY instruction copies new files or
directories from <src> and adds them to the filesystem of the container
at the path <dest>.
Multiple <src> resources may be specified
but the paths of files and directories will be interpreted as relative to the
source of the context of the build.
Each <src> may contain wildcards and
matching will be done using Go’s filepath.Match rules. For example:
COPY test.txt relativeDir/
ADD
The ADD instruction copies new files,
directories or remote file URLs from <src> and adds them to the filesystem
of the image at the path <dest>.
Multiple <src> resources may be specified
but if they are files or directories, their paths are interpreted as relative
to the source of the context of the build.
eg: To add all the files starting with
"sye"
ADD sye* /mydir/
CMD
The main purpose of a CMD is to provide
defaults for an executing container. These defaults can include an executable,
or they can omit the executable, in which case you must specify an ENTRYPOINT
instruction as well.
If CMD is used to provide default arguments for
the ENTRYPOINT instruction, both the CMD and ENTRYPOINT instructions should be
specified with the JSON array format.
eg:
FROM ubuntu
CMD echo "This is a test." | wc -
ENTRYPOINT
An ENTRYPOINT allows you to configure a
container that will run as an executable.
eg:
ENTRYPOINT
["java","-jar","/app.jar"]
ENV
The ENV instruction sets the environment
variable <key> to the value <value>. This value will be in the
environment for all subsequent instructions in the build stage and can be
replaced inline in many as well.
eg:
ENV myName="Syed Ghouse"
EXPOSE
The EXPOSE instruction informs Docker that the
container listens on the specified network ports at runtime. You can specify
whether the port listens on TCP or UDP, and the default is TCP if the protocol
is not specified.
The EXPOSE instruction does not actually
publish the port. It functions as a type of documentation between the person
who builds the image and the person who runs the container, about which ports
are intended to be published. To actually publish the port when running the
container, use the -p flag on docker run to publish and map one or more ports,
or the -P flag to publish all exposed ports and map them to high-order ports.
eg:
EXPOSE 80/udp
FROM
The FROM instruction initializes a new build
stage and sets the Base Image for subsequent instructions. As such, a valid
Dockerfile must start with a FROM instruction. The image can be any valid image
– it is especially easy to start by pulling an image from the Public
Repositories.
eg:FROM openjdk:8-jdk-alpine
FROM instructions support variables that are
declared by any ARG instructions that occur before the first FROM
An ARG declared before a FROM is outside of a
build stage, so it can’t be used in any instruction after a FROM. To use the
default value of an ARG declared before the first FROM use an ARG instruction
without a value inside of a build stage:
eg:
ARG VERSION=latest
FROM busybox:$VERSION
ARG VERSION
RUN echo $VERSION > image_version
MAINTAINER
The MAINTAINER instruction sets the Author
field of the generated images. The LABEL instruction is a much more flexible
version of this and you should use it instead, as it enables setting any
metadata you require, and can be viewed easily, for example with docker
inspect. To set a label corresponding to the MAINTAINER field you could use
eg: LABEL
maintainer="syedghouse14@gmail.com"
RUN
The RUN instruction will execute any commands
in a new layer on top of the current image and commit the results. The
resulting committed image will be used for the next step in the Dockerfile.
eg:
RUN ["/bin/bash", "-c",
"echo hello"]
USER sets the UID (or username) which is to run the container.
VOLUME is used to enable access from the container to
a directory on the host machine.
WORKDIR sets the path where the
command, defined with CMD, is to be executed.
LABEL
The LABEL instruction adds metadata to an
image. A LABEL is a key-value pair. To include spaces within a LABEL value, use
quotes and backslashes as you would in command-line parsing.
eg: LABEL version="1.0"
Thursday, 11 June 2020
Spring Boot With Docker
We will See in this post how to create a docker image and run from it. Of course, it is available in the spring site as a tutorial. I am providing here my version of achieving it.
ARG JAR_FILE=target/*.jar
COPY ${JAR_FILE} app.jar
ENTRYPOINT ["java","-jar","/app.jar"]
That’s all Congrats on your first docker app.
Labels
- Android
- ANT BUILD
- ATG
- CAS
- Docker
- Endeca Assembler
- Endeca Errors
- Endeca Interview
- Error
- Fresher
- Indexing
- Installation
- Interview
- JAVA
- Java Interview
- JavaFx
- JAX-RS
- Jenkins
- kubernetes
- Lenovo
- Linux
- MachineLearning
- Maven
- MicroServices
- Microservices Interview
- Migration
- Oracle cloud
- Solr Interview
- SOLR Search
- spring boot
- Spring Framework
- Spring Interview
- struts
- Weblogic
- Wildfly
- Wishes
- XML Parser