I want to use Maven in my Docker image.
After looking here https://hub.docker.com/_/maven/ , I tried using this Dockerfile:
FROM openjdk:7
RUN apk add --no-cache curl tar bash
ARG MAVEN_VERSION=3.3.9
ARG USER_HOME_DIR="/root"
RUN mkdir -p /usr/share/maven /usr/share/maven/ref \
&& curl -fsSL http://apache.osuosl.org/maven/maven-3/$MAVEN_VERSION/binaries/apache-maven-$MAVEN_VERSION-bin.tar.gz \
| tar -xzC /usr/share/maven --strip-components=1 \
&& ln -s /usr/share/maven/bin/mvn /usr/bin/mvn
ENV MAVEN_HOME /usr/share/maven
ENV MAVEN_CONFIG "$USER_HOME_DIR/.m2"
COPY mvn-entrypoint.sh /usr/local/bin/mvn-entrypoint.sh
COPY settings-docker.xml /usr/share/maven/ref/
VOLUME "$USER_HOME_DIR/.m2"
ENTRYPOINT ["/usr/local/bin/mvn-entrypoint.sh"]
CMD ["mvn"]
However, I'm getting:
lstat mvn-entrypoint.sh: no such file or directory
I tried different Dockerfiles from the same repositories but they all throw this error.
What's wrong with this dockerfile? How can I use Maven with Docker?
Try this:
Dockerfile:-
FROM openjdk:8u111-jdk-alpine
COPY assets/settings.xml /tmp/settings.xml
ENV PATH=$PATH:/opt/maven/bin
RUN apk add --no-cache curl tar bash && \
curl -SsL -o /tmp/maven.tar.gz http://www-us.apache.org/dist/maven/maven-3/3.3.9/binaries/apache-maven-3.3.9-bin.tar.gz && \
mkdir -p /opt && \
tar xzf /tmp/maven.tar.gz -C /opt/ && \
ln -s /opt/apache-maven-3.3.9 /opt/maven && \
rm /tmp/maven.tar.gz && \
mv /tmp/settings.xml /opt/maven/conf/settings.xml
You need to put this Dockerfile in a new directory, with a subdirectory called 'assets', and you need to put a maven settings file ( settings.xml
) in that directory. If you don't have a custom settings file then remove the COPY
and the mv
.
Build it with something like
docker --tag ajava8 .
You can run maven in your current directory using something like:
docker run -it --rm -v /$PWD:/work -w /work ajava8 mvn clean install
Or, you can get a bash shell with something similar, like this:
docker run -it --rm -v /$PWD:/work -w /work ajava8 bash
我只是遇到了同样的问题,我忘了下载“ mvn-entrypoint.sh”文件。.https ://github.com/carlossg/docker-maven/tree/322d0dff5d0531ccaf47bf49338cb3e294fd66c8/jdk-8 ..也是设置-docker.xml是必需的。
You need the files copied in the Dockerfile mvn-entrypoint.sh
and settings-docker.xml
. You can git clone from https://github.com/carlossg/docker-maven
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.