I have created a dockerfile and docker-compose like below, which is suppost to create an image of tomcat inside my container and edit the tomcat users so that I am able to access the manager gui.
The four files below are all in the same folder as where I run the docker-compose up command.
docker-compose.yml
version: '2'
services:
tomcat:
build: .
container_name: development
ports:
- 8001:8080
environment:
- spring.profiles.active=development
Dockerfile
FROM tomcat
COPY tomcat-users.xml /usr/local/tomcat/conf/
COPY context.xml /usr/local/tomcat/webapps/manager/META-INF/
CMD ["catalina.sh","run"]
tomcat-users.xml
<?xml version='1.0' encoding='cp1252'?>
<tomcat-users xmlns="http://tomcat.apache.org/xml"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://tomcat.apache.org/xml tomcat-users.xsd"
version="1.0">
<user username="manager" password="pass" roles="manager-gui,manager-script"/>
<user username="admin" password="pass" roles="tomcat"/>
</tomcat-users>
context.xml
<?xml version="1.0" encoding="UTF-8"?>
<Context antiResourceLocking="false" privileged="true" >
<!--<Valve className="org.apache.catalina.valves.RemoteAddrValve"
allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" />-->
</Context>
when I run the command docker-compose up, it generates the container with a tomcat image perfectly, but the existing tomcat-users.xml and context.xml didn't get overwritten. Any idea what I'm doing wrong to overwrite those two files?
I figured it out. The problem was that the user with which I was executing the build tasks did not have sufficient rights to write stuff in those folders. What I did was add a USER root task to the Dockerfile so it executes all the commands as root.
My Dockerfile now looks like this: