Docker的ADD指令未在Windows机器上运行

时间:2019-03-13 11:09:41

标签: docker dockerfile

我正在尝试执行其中有添加命令的Docker文件

FROM openjdk:11.0.2-jre-slim


EXPOSE 8080
EXPOSE 4040

VOLUME /data

RUN apt-get update && apt-get install -y dos2unix

# main application JAR
ADD target/service.jar app.jar
# wrapper that executes the JVM
ADD bin/run.sh run.sh
#add the ui dist folder
ADD target/static static


RUN dos2unix /run.sh && apt-get --purge remove -y dos2unix && rm -rf /var/lib/apt/lists/*

ADD bin/java-buildpack-memory-calculator-linux-3.9.0 memory-calculator

RUN chmod +x run.sh
RUN chmod +x memory-calculator


ENTRYPOINT exec ./run.sh

第一个命令运行正常,但是第二个命令ADD target/static static给出错误

ADD failed: stat /var/lib/docker/tmp/docker-builder231151249/target/static: no such file or directory

同一命令在Mac OS上有效,但在Windows上无效。不知道这是怎么回事? 文件夹结构为

|
|
|-------Dockerfile
|-------target
          |
          |
          |----------static
                        |
                        |
                        |---------html,js files

1 个答案:

答案 0 :(得分:0)

尝试将./target/static添加到Dockerfile中,例如:

# wrapper that executes the JVM 
ADD bin/run.sh run.sh 
#add the ui dist folder 
ADD ./target/static static

也请尝试使用COPY命令,而不要添加:

  # wrapper that executes the JVM 
    COPY  bin/run.sh run.sh 
    #add the ui dist folder 
    COPY ./target/static/ static/

并运行docker命令,如:

docker build --no-cache ....

尝试将其添加到Dockerfile

 RUN mkdir -p /target/static/
 # wrapper that executes the JVM 
 COPY  bin/run.sh run.sh 
 #add the ui dist folder 
 COPY ./target/static/ /target/static/

建立测试结果:

Step 5/5 : ADD ./target/static/ static
 ---> 712e06b2d81c
Successfully built 712e06b2d81c
Successfully tagged test:latest

我仅有的其他建议是检查行尾,并确保文件名中没有多余的空格,例如 ADD target / static或static末尾的空格

您是否希望target/static/文件位于容器的/static中? 要么 ... 在容器中的/target/static