【发布时间】:2018-01-21 11:32:35
【问题描述】:
我正在尝试构建一个 Java 应用程序并使用 docker 制作一个包。这个构建需要一个我不想包含在图像中的 Maven 存储库,因为它非常大。我想尝试使用卷并将我的本地 maven 存储库安装到映像中的 maven 存储库。我使用apt-get install -y maven 以使maven 可用,但在图像$HOME 中找不到目录.m2。
我使用ls -la $HOME、ls -la和ls -la /root找到了maven home,但是那里没有.m2目录。
编辑 1:
我在Dockerfile 中有这些行:
FROM ubuntu
MAINTAINER Zeinab Abbasimazar
# Install and configure required packages
RUN apt-get update; \
apt-get install -y --no-install-recommends apt-utils; \
apt-get install -y dialog; \
apt-get install -y wget unzip curl maven; \
mkdir $HOME/.m2/; \
ls -la /usr/share/maven/conf/; \
echo \
"<settings xmlns='http://maven.apache.org/SETTINGS/1.0.0\' \
xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' \
xsi:schemaLocation='http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd'> \
<localRepository>/root/.m2/repository</localRepository> \
<interactiveMode>true</interactiveMode> \
<usePluginRegistry>false</usePluginRegistry> \
<offline>false</offline> \
</settings>" \
> /usr/share/maven/conf/settings.xml
VOLUME ["/home/zeinab/.m2/", "/root/.m2/"]
# Build
RUN mvn -X clean install -pl components -P profile
它将本地存储库配置放入映像的 maven 配置文件中,将我的本地 maven 存储库安装到映像中的目录并最终执行构建。正如我在 Maven 构建日志中看到的那样,它正在使用我期望的本地存储库路径:
[DEBUG] Reading global settings from /usr/share/maven/conf/settings.xml
[DEBUG] Reading user settings from /root/.m2/settings.xml
[DEBUG] Using local repository at /root/.m2/repository
但仍然无法检测到依赖关系。
【问题讨论】:
-
为什么不在 docker 容器之外构建应用程序,然后将结果复制到容器中?
-
能否请您发布完整的错误日志。
-
我同意@khmarbaise - 在 Docker 之外构建应用程序会容易得多。
-
@khmarbaise,我想过这个;但我更喜欢在同一个镜像中构建和打包,以便进行集成。
-
@Akash,没有错误。我说我在搜索
.m2目录,但是找不到。
标签: java maven docker dockerfile docker-build