docker文件使用docker文件配置tomcat

rqqzpn5f  于 2023-02-11  发布在  Docker
关注(0)|答案(1)|浏览(118)

我想用tomcat服务器创建一个docker文件。我有两个war文件war 1和war 2。我将war1.xml复制到/usr/local/tomcat/conf/ Catalina /localhost/我将war2.xml复制到/usr/local/tomcat/conf/Catalina/localhost/
下面是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>

以下是我的Docker文件:

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"]

下面是mysql docker文件:

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

但上下文无法添加数据源,我有以下错误:

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

原因:数据源查找失败异常:查找名为“app 1”的JNDI数据源失败;嵌套异常是javax。命名。名称未发现异常:名称[app 1]未绑定到此上下文中。找不到[app 1]。

l3zydbqr

l3zydbqr1#

问题出在JNDI-NAME,在属性文件中,您应该给予server.xml中定义的完整名称:jndi/datasourceName没有引号。这不是docker的问题。谢谢

相关问题