Docker tomcat通过dockerfile编辑配置文件 [英] Docker tomcat editing configuration files through dockerfile

查看:218
本文介绍了Docker tomcat通过dockerfile编辑配置文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了一个dockerfile和docker-compose,如下所示,这是在容器内创建tomcat图像并编辑tomcat用户的后缀,以便我能够访问manager gui。

下面的四个文件都与运行 docker-compose up 命令的位置相同。

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>  

当我运行命令 docker-compose up 时,它将生成容器带有完美的tomcat图像,但是现有的tomcat-users.xml和context.xml不会被覆盖。知道我为覆盖这两个文件做错了什么吗?

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?

推荐答案

我知道了。问题是与我一起执行构建任务的用户没有足够的权限在那些文件夹中写东西。我所做的就是在Dockerfile中添加一个 USER root 任务,以便它以root身份执行所有命令。

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.

我的Dockerfile现在看起来像这样:

My Dockerfile now looks like this:

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

这篇关于Docker tomcat通过dockerfile编辑配置文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆