我的docker文件中包含以下代码段:
...
ADD app.war /opt/apache-tomcat-8.5.14/webapps/app.war
...
但是,将docker映像输入为:
docker exec -it tomcat /bin/sh
并在ls
文件夹中进行webapps
,文件不存在。在我的本地操作系统Windows中,该文件与dockerfile位于同一文件夹中。关于发生这种情况的任何线索?
编辑:
但是,在我的Windows cmd中使用cp
命令,检入容器后它可以正常工作。
dockerfile:
FROM alpine:latest
MAINTAINER Adilson Cesar <adilsonbna@gmail.com>
# Expose Web Port
EXPOSE 8080
# Set environment
ENV JAVA_HOME /opt/jdk
ENV PATH ${PATH}:${JAVA_HOME}/bin
ENV JAVA_PACKAGE server-jre
ENV TOMCAT_VERSION_MAJOR 8
ENV TOMCAT_VERSION_FULL 8.5.14
ENV CATALINA_HOME /opt/tomcat
# Download and install Java
RUN apk --update add openjdk8-jre &&\
mkdir -p /opt/jdk &&\
ln -s /usr/lib/jvm/java-1.8-openjdk/bin /opt/jdk
# Download and install Tomcat
RUN apk add --update curl &&\
curl -LO https://archive.apache.org/dist/tomcat/tomcat-${TOMCAT_VERSION_MAJOR}/v${TOMCAT_VERSION_FULL}/bin/apache-tomcat-${TOMCAT_VERSION_FULL}.tar.gz &&\
curl -LO https://archive.apache.org/dist/tomcat/tomcat-${TOMCAT_VERSION_MAJOR}/v${TOMCAT_VERSION_FULL}/bin/apache-tomcat-${TOMCAT_VERSION_FULL}.tar.gz.md5 &&\
md5sum -c apache-tomcat-${TOMCAT_VERSION_FULL}.tar.gz.md5 &&\
gunzip -c apache-tomcat-${TOMCAT_VERSION_FULL}.tar.gz | tar -xf - -C /opt &&\
rm -f apache-tomcat-${TOMCAT_VERSION_FULL}.tar.gz apache-tomcat-${TOMCAT_VERSION_FULL}.tar.gz.md5 &&\
ln -s /opt/apache-tomcat-${TOMCAT_VERSION_FULL} /opt/tomcat &&\
rm -rf /opt/tomcat/webapps/examples /opt/tomcat/webapps/docs &&\
apk del curl &&\
rm -rf /var/cache/apk/*
ADD app.war /opt/apache-tomcat-8.5.14/webapps/
# Launch Tomcat on startup
CMD ${CATALINA_HOME}/bin/catalina.sh run
谢谢!
答案 0 :(得分:2)
尽管docker docs另有建议
If <dest> does not end with a trailing slash, it will be considered a regular file and the contents of <src> will be written at <dest>
通过删除目标文件名来尝试此操作。应该可以。
ADD app.war /opt/apache-tomcat-8.5.14/webapps/
另外,从Docker Best Practices开始,如果您只是复制本地文件而不使用远程URL,则建议使用COPY而不是ADD。
Although ADD and COPY are functionally similar, generally speaking, COPY is preferred. That’s because it’s more transparent than ADD