Showing posts with label Docker. Show all posts
Showing posts with label Docker. Show all posts

Thursday 29 July 2021

ORA-01882: timezone region not found in Docker

This Issue comes when the development environment and the DB Environment are different.

For Eg: I have my Local Box running in the IST Zone and the docker container in UTC Zone. Hence I arrived at this error.

To Resolve this Follow the below steps.

Create the file docker-compose.yml

version:'3'

services:
  app:
    build: .
    image: my-image
    ports:
      - "8084:8084"
    environment:
  - TZ="Asia/Kolkata"


In the above docker-compose file, I mentioned the environment variable TZ as "Asia/Kolkata". Thes Time zones can be found from the link.

Building and Starting the Docker Image

Use docker compose up

It will start the image without this Error.

Happy Solvings!!!!

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. 





Happy Learning!!!!



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




Step1: Create the Docker credentials in Jenkins.


Navigate to Dashboard and  Select Manage Jenkins



Step2: Select Manage credentials.




Step:3 Create Credentials.

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"

      }

    }

  }

}


Step:5 Execute Success



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 !!!!