i want to create a docker file with tomcat server . i have two war files war 1 and war 2. i copied war1.xml into /usr/local/tomcat/conf/Catalina/localhost/ i copied war2.xml into /usr/local/tomcat/conf/Catalina/localhost/
here is the context of war1.xml
<Resources>
<Resource
name="jdbc/app1"
type="javax.sql.DataSource"
auth="Container"
username="root"
password="toto"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306">
</Resource>
<PreResources className="org.apache.catalina.webresources.DirResourceSet" base="/app/ml/ts/config/"
webAppMount="/WEB-INF/classes"/>
<ResourceLink global="app1" name="app1" type="javax.sql.DataSource"/>
</Resources>
here are my docker files :
FROM tomcat:8.0-jre8-alpine
COPY app1/target/war1.war /usr/local/tomcat/webapps/
COPY app2/target/app2.war /usr/local/tomcat/webapps/
COPY app1/src/main/resources/conf/app1.xml /usr/local/tomcat/conf/Catalina/localhost/
COPY app2/src/main/resources/app2/conf/app2.xml /usr/local/tomcat/conf/Catalina/localhost/
COPY app1/src/main/resources/app1/scripts/*
EXPOSE 8080
CMD ["catalina.sh","run"]
here is mysql docker file :
FROM mysql:5.7
# Add a database
ENV MYSQL_DATABASE MyDb
ENV MYSQL_ROOT_PASSWORD toto
# Add the content of the sql-scripts/ directory to your image
# All scripts in docker-entrypoint-initdb.d/ are automatically
# executed during container startup
COPY app-livraison/src/main/resources/db/ /docker-entrypoint-initdb.d/
here is my docker compose file :
version: '3'
services:
tomcat:
build:
context: .
dockerfile: Dockerfile.tomcat
ports:
- 8080:8080
mysql:
build:
context: .
dockerfile: Dockerfile.db
environment:
MYSQL_ROOT_PASSWORD: toto
MYSQL_DATABASE: Mydb
but the context could not add the datasource , i have the following error :
BeanInstantiationException: Failed to instantiate [javax.sql.DataSource]: Factory method 'dataSource' threw exception; nested exception is org.springframework.jdbc.datasource.lookup.DataSourceLookupFailureException: Failed to look up JNDI DataSource with name '"glc-batch"'; nested exception is javax.naming.NameNotFoundException: Name [app1] is not bound in this Context. Unable to find [app1].
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185)
at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:653)
... 48 common frames omitted
Caused by: org.springframework.jdbc.datasource.lookup.DataSourceLookupFailureException: Failed to look up JNDI DataSource with name '"app1"'; nested exception is javax.naming.NameNotFoundException: Name [app1] is not bound in this Context. Unable to find [app1].
the problem was the JNDI-NAME , in the properties file you should give the complete name defined in server.xml : jndi/datasourceName without quotation marks. that was not a docker problem. thanks