Deploy Cuba in tomcat8 --> Name [jdbc/CubaDS] is not bound in this Context

I try to deploy simple CUBA app in Docker with Tomcat 8.5
Dockerfile:


FROM debian

ENV DEBIAN_FRONTEND noninteractive
RUN apt-get update

## Set Timezone to UTC
RUN echo "UTC" > /etc/timezone;\
    dpkg-reconfigure -f noninteractive tzdata

## Set LOCALE to ru_RU.UTF8
RUN apt-get install -y locales;\
    sed -i -e 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen;\
    sed -i -e 's/# ru_RU.UTF-8 UTF-8/ru_RU.UTF-8 UTF-8/' /etc/locale.gen;\
    echo 'LANG="ru_RU.UTF-8"'>/etc/default/locale;\
    dpkg-reconfigure --frontend=noninteractive locales;\
    update-locale LANG=ru_RU.UTF-8

# Add jessie-backports
RUN echo '\n#backports\n' | tee -a /etc/apt/sources.list;\
    echo "deb http://http.debian.net/debian jessie-backports main" | tee -a /etc/apt/sources.list;\
    apt-get update

# linux utils install
RUN apt-get install -y zip aptitude software-properties-common nano mc curl net-tools wget unzip

# java install
RUN aptitude -y -t jessie-backports install openjdk-8-jdk;\
    lastJavaHome=$(find /usr/lib/jvm -maxdepth 1 -type d -name '*openjdk*' | head -n 1);\
    echo "export JAVA_HOME=$lastJavaHome" | tee -a /etc/profile.d/environment.sh;\
    echo 'PATH=$PATH:$JAVA_HOME/bin' | tee -a /etc/profile.d/environment.sh

## tomcat install
RUN apt-get update;\
    aptitude upgrade -y;\
    aptitude -y -t jessie-backports install tomcat8 tomcat8-user tomcat8-admin libservlet3.1-java;\
    service tomcat8 stop

ENV TOMCAT_HOME "/var/lib/tomcat8"

## cuba install

### Create context.xml                   --  I TRIED WITHOUT IT. NOTHING CHANGES.
COPY context.xml ${TOMCAT_HOME}/conf/Catalina/localhost/app.xml
RUN chown root:tomcat8 ${TOMCAT_HOME}/conf/Catalina/localhost/app.xml

### Create app_home
RUN mkdir /opt/cuba;\
    chown tomcat8:tomcat8 /opt/cuba

USER tomcat8
COPY app.war ${TOMCAT_HOME}/webapps
COPY app-core.war ${TOMCAT_HOME}/webapps

# start
USER root
CMD service tomcat8 start;\
    /bin/bash

I take context.xml from modules/core/web/META-INF:


<Context>
    <!-- Database connection -->
    <Resource driverClassName="org.postgresql.Driver"
              maxIdle="2"
              maxTotal="20"
              maxWaitMillis="5000"
              name="jdbc/CubaDS"
              password="supersecurepassword"
              type="javax.sql.DataSource"
              url="jdbc:postgresql://localhost/cuba"
              username="userrr"/>
    <!-- Switch off session serialization -->
    <Manager pathname=""/>
    <!--<Resource driverClassName="org.hsqldb.jdbc.JDBCDriver"
          maxIdle="2"
          maxTotal="20"
          maxWaitMillis="5000"
          name="jdbc/CubaDS"
          password=""
          type="javax.sql.DataSource"
          url="jdbc:hsqldb:hsql://localhost/cuba"
          username="sa"/>-->
</Context>

Build part of gradle:


task buildWar(type: CubaWarBuilding) {
    appHome = '/opt/cuba'
    appProperties = ['cuba.automaticDatabaseUpdate': 'true']
    singleWar = false
}

And all this ends with error in catalina.out:


Caused by: javax.naming.NameNotFoundException: Name [jdbc/CubaDS] is not bound in this Context. Unable to find [jdbc].
        at org.apache.naming.NamingContext.lookup(NamingContext.java:816) ~[tomcat8-catalina-8.5.11.jar:8.5.11]
        at org.apache.naming.NamingContext.lookup(NamingContext.java:173) ~[tomcat8-catalina-8.5.11.jar:8.5.11]
        at org.apache.naming.SelectorContext.lookup(SelectorContext.java:163) ~[tomcat8-catalina-8.5.11.jar:8.5.11]
        at javax.naming.InitialContext.lookup(InitialContext.java:417) ~[na:1.8.0_121]
        at org.springframework.jndi.JndiTemplate$1.doInContext(JndiTemplate.java:155) ~[spring-context-4.3.3.RELEASE.jar:4.3.3.RELEASE]
        at org.springframework.jndi.JndiTemplate.execute(JndiTemplate.java:87) ~[spring-context-4.3.3.RELEASE.jar:4.3.3.RELEASE]
        at org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:152) ~[spring-context-4.3.3.RELEASE.jar:4.3.3.RELEASE]
        at org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:179) ~[spring-context-4.3.3.RELEASE.jar:4.3.3.RELEASE]
        at org.springframework.jndi.JndiLocatorSupport.lookup(JndiLocatorSupport.java:104) ~[spring-context-4.3.3.RELEASE.jar:4.3.3.RELEASE]
        at org.springframework.jndi.JndiObjectLocator.lookup(JndiObjectLocator.java:106) ~[spring-context-4.3.3.RELEASE.jar:4.3.3.RELEASE]
        at org.springframework.jndi.JndiObjectFactoryBean.lookupWithFallback(JndiObjectFactoryBean.java:231) ~[spring-context-4.3.3.RELEASE.jar:4.3.3.RELEASE]
        at org.springframework.jndi.JndiObjectFactoryBean.afterPropertiesSet(JndiObjectFactoryBean.java:217) ~[spring-context-4.3.3.RELEASE.jar:4.3.3.RELEASE]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1642) ~[spring-beans-4.3.3.RELEASE.jar:4.3.3.RELEASE]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1579) ~[spring-beans-4.3.3.RELEASE.jar:4.3.3.RELEASE]
        ... 40 common frames omitted

What am I missing?

If you provide context.xml outside of WAR in the conf/Catalina/localhost folder, it should have the app-core.xml name because it is used by the app-core web application.

Alternatively, you can include it into WAR by specifying the includeContextXml and coreContextXmlPath parameters of the buildWar task. There are also corresponding elements on the Deployment Settings page in Studio.