0

After running docker build -t it/spring-boot-docker-jdbc . finished successfully I am trying to run-

docker run -p 8080:8080 it/spring-boot-docker-jdbc

and I get NameNotFound error -

Caused by: javax.naming.NameNotFoundException: Name [jdbc/SubscriptionServicesDataSource] is not bound in this Context. Unable to find [jdbc].
        at org.apache.naming.NamingContext.lookup(NamingContext.java:817) ~[tomcat-embed-core-8.5.23.jar!/:8.5.23]
        at org.apache.naming.NamingContext.lookup(NamingContext.java:173) ~[tomcat-embed-core-8.5.23.jar!/:8.5.23]
        at org.apache.naming.SelectorContext.lookup(SelectorContext.java:163) ~[tomcat-embed-core-8.5.23.jar!/:8.5.23]
        at javax.naming.InitialContext.lookup(InitialContext.java:417) ~[na:1.8.0_212]
        at org.springframework.jndi.JndiTemplate$1.doInContext(JndiTemplate.java:155) ~[spring-context-4.3.13.RELEASE.jar!/:4.3.13.RELEASE]
        at org.springframework.jndi.JndiTemplate.execute(JndiTemplate.java:87) ~[spring-context-4.3.13.RELEASE.jar!/:4.3.13.RELEASE]
        at org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:152) ~[spring-context-4.3.13.RELEASE.jar!/:4.3.13.RELEASE]
        at org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:179) ~[spring-context-4.3.13.RELEASE.jar!/:4.3.13.RELEASE]
        at org.springframework.jndi.JndiLocatorSupport.lookup(JndiLocatorSupport.java:104) ~[spring-context-4.3.13.RELEASE.jar!/:4.3.13.RELEASE]
        at org.springframework.jndi.JndiObjectLocator.lookup(JndiObjectLocator.java:106) ~[spring-context-4.3.13.RELEASE.jar!/:4.3.13.RELEASE]
        at org.springframework.jndi.JndiObjectTargetSource.getTarget(JndiObjectTargetSource.java:135) ~[spring-context-4.3.13.RELEASE.jar!/:4.3.13.RELEASE]
        ... 74 common frames omitted

All the connection properties are in application.properties and it runs as expected outside when running locally outside the image. My Dockerfile-

FROM openjdk:8-jdk-alpine
ARG JAR_FILE=target/*.jar
COPY ${JAR_FILE} app.jar
ENTRYPOINT ["java","-jar","/app.jar"]

JDBC dependencies-

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
    <groupId>com.oracle</groupId>
    <artifactId>ojdbc7</artifactId>
    <version>1.0</version>
</dependency> 

Application.properties

#DB Properties
database.datasources[0].jndi-name=jdbc/SubscriptionServicesDataSource
database.datasources[0].username=xxxUnameXXX //fake
database.datasources[0].password=xxxPassxxx //fake
database.datasources[0].url=jdbc:oracle:thin:@localhost:21521:webtst
database.datasources[0].driverClassName=oracle.jdbc.OracleDriver
database.datasources[0].factory=org.apache.tomcat.jdbc.pool.DataSourceFactory
database.datasources[0].initialSize=1
database.datasources[0].maxActive=15
Itsik Mauyhas
  • 3,824
  • 14
  • 69
  • 114

0 Answers0