简体   繁体   中英

Docker image cannot read / find a .jar file from another image?

I am new to both Java and Docker. I have two Git repositories:

  • project-cms
  • project-app

Both repositories are Java projects. My instructions are to mvn clean install from project-cms and then mvn clean install && mvn build from project-app so that project-app can use the .war file generated by project-cms. I am trying to Dockerize this setup by creating an image of project-cms like this:

FROM maven:3.5.2-jdk-8-alpine
LABEL Name=project-cms Version=1.0.0 

# Container configuration
RUN mkdir /project-cms
COPY . /project-cms
WORKDIR /project-cms
VOLUME /project-cms
RUN mvn clean install

This works fine and I now see an image called project-cms:latest when I do docker image ls . I am trying to use this image to build my project-app like this:

FROM project-cms:latest
LABEL Name=project-app Version=1.0.0 

# Container configuration
RUN mkdir /app
COPY . /app
WORKDIR /app
VOLUME /app
RUN mvn clean install && mvn build
EXPOSE 8080
CMD [ "mvn", "tomcat7:run" ]

My understanding is that the .war file from project-cms should be available to project-app since I am running FROM project-cms:latest above. When I try to build this image, it throws the following error:

[ERROR] Failed to execute goal on project xxxx: Could not resolve dependencies for project com.xxxx:xxxx:war:2.28.1: Could not find artifact com.xxxx:publishing-site:jar:classes:1.02.26 in hippo (http://maven.onehippo.com/maven2/) -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/DependencyResolutionException
The command '/bin/sh -c mvn clean install && mvn build' returned a non-zero code: 1

Please note that I have redacted the actual project name with xxxx in the error message above. My thought was to host the project-cms Docker image in our AWS Elastic Container Service so that other developers could just pull that image to build project-app instead of manually installing Maven etc. on each developer machine. Any help to resolve this is appreciated.

the maven local repo is a volume in previous versions of the image, removed in https://github.com/carlossg/docker-maven/pull/57

it should work if you use FROM maven:3.5-jdk-8-alpine

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM