[英]Docker tomcat editing configuration files through dockerfile
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. 我已经创建了一个dockerfile和docker-compose,如下所示,它可以在我的容器中创建一个tomcat图像并编辑tomcat用户,以便我能够访问管理器gui。
The four files below are all in the same folder as where I run the docker-compose up command. 下面的四个文件都与我运行docker-compose up命令的文件夹相同。
docker-compose.yml 泊坞窗,compose.yml
version: '2'
services:
tomcat:
build: .
container_name: development
ports:
- 8001:8080
environment:
- spring.profiles.active=development
Dockerfile 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 的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 的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. 当我运行命令docker-compose up时 ,它会完美地生成带有tomcat图像的容器,但是现有的tomcat-users.xml和context.xml没有被覆盖。 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.
我所做的是将一个USER根任务添加到Dockerfile,以便它以root身份执行所有命令。
My Dockerfile now looks like this: 我的Dockerfile现在看起来像这样:
FROM tomcat
USER root
COPY tomcat-users.xml /usr/local/tomcat/conf/
COPY context.xml /usr/local/tomcat/webapps/manager/META-INF/
CMD ["catalina.sh","run"]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.