The easiest way would be copy your *.war file to webapps folder with desired name. It can be easily done, by modifying line:
COPY ./my.war /opt/tomcat/webapps/
to
COPY ./my.war /opt/tomcat/webapps/myContext.war
This change would make your app available under <server>:<port>/myContext
path. If you wish to have context path specified under environment variable, you can modify your script to:
ENV MY_CONTEXT=contextName
COPY ./my.war /opt/tomcat/webapps/${MY_CONTEXT}.war
Setting up application context explicitly with Tomcat means can be done with these steps:
Go to your application META-INF folder (in your case: /opt/tomcat/webapps/my/META-INF)
Create XML file: context.xml
and paste this content:
<?xml version="1.0" encoding="UTF-8"?>
<Context antiJARLocking="true" path="/myContext"/>
- Restart Tomcat
With some effort you should be able to automate these steps in your Dockerfile.