Dockerfile,运行 git 克隆未创建所需 files/folders

Dockerfile, RUN git clone does not create required files/folders

英语不是我的母语,所以我提前为可能出现的错误道歉。

我是 Docker 和 Linux 的新手,正在尝试学习 rn。 我有一个任务,我需要基于 tomcat:9.0-alpine 创建 dockerfile,然后在这个确切的文件中克隆提供的存储库。然后我需要从这个 dockerfile、运行 容器构建图像,然后在浏览器中访问 index.html,在那里我将看到一个特定的页面。 这是我的 dockerfile 的样子:

FROM tomcat:9.0-alpine
RUN apk update
RUN apk add git
RUN git clone https://github.com/a1qatraineeship/docker_task.git $TOMCAT_HOME/webapps/whateverApp/

当我从这里构建图像时,我看到 repo 被克隆到我指定的目录中:

#7 [4/4] RUN git clone https://github.com/a1qatraineeship/docker_task.git $TOMCAT_HOME/webapps/aquaApp/
#7 sha256:72b802c3b98dad7151daeba7db257b7b1f1089dc26fb5809fee52f881e19edb5
#7 0.319 Cloning into '/webapps/whateverApp'...
#7 DONE 1.9s

但是当我 运行 容器并转到 http://localhost:8888/whateverApp/ 时,我得到“404 - 未找到”。 如果我去 http://localhost:8888,我会看到 Tomcat 默认页面,所以 Tomcat 确实有效。 如果我 bash 进入容器并转到 /webapps - 我在那里没有看到我指定的文件夹 (whateverApp)。

我错过了什么?一切似乎工作正常,没有抛出任何错误,但没有看到所谓的克隆存储库。在我看到的示例中,没有提及任何访问限制或其他内容。甚至我的老师之前也说过,整个 dockerfile 基本上由 4 行组成,而我真正需要找出的唯一一件事就是克隆 repo 到哪里才能使一切正常工作。但如果它根本没有克隆,我如何验证我是否将文件放在正确的位置?

问题是你的环境变量,当容器为空时运行TOMCAT_HOME

FROM tomcat:9.0-alpine
ENV TOMCAT_HOME=/usr/local/tomcat
RUN apk update
RUN apk add git
RUN git clone https://github.com/a1qatraineeship/docker_task.git $TOMCAT_HOME/webapps/whateverApp/

这样 ENV 就可以了,祝你好运!