在docker中构建镜像时出现以下错误:
docker build -t demo .
输出 :
Sending build context to Docker daemon 2.048kB
Step 1/3 : From tomcat:8
---> 8973f493aa0a
Step 2/3 : MAINTAINER "shweta"
---> Using cache
---> 4b846800a044
Step 3/3 : COPY ./webapp.war /usr/local/tomcat/webapps
错误 :
COPY failed: stat /var/lib/docker/tmp/docker-builder389027616/webapp.war: no such file o r directory
Docker文件:
# Pull base image
From tomcat:8
# Maintainer
MAINTAINER "shweta"
# copy war file on to container
COPY ./webapp.war /usr/local/tomcat/webapps
答案1
您应该始终docker build
从文件所在的目录运行命令webapp.war
。
.
in./webapp.war
告诉docker build
命令在当前目录中查找文件。
没有webapp.war
在当前目录中。
docker build -f Dockerfile .
输出 :
Sending build context to Docker daemon 748kB
Step 1/3 : From tomcat:8
8: Pulling from library/tomcat
092586df9206: Pull complete
ef599477fae0: Pull complete
4530c6472b5d: Pull complete
d34d61487075: Pull complete
272f46008219: Pull complete
12ff6ccfe7a6: Pull complete
f26b99e1adb1: Pull complete
21bec9c8ea28: Pull complete
b8a32f28e27c: Pull complete
94fdd0ba0430: Pull complete
Digest: sha256:bb4ceffaf5aa2eba6c3ee0db46d863c8b23b263cb547dec0942e757598fd0c24
Status: Downloaded newer image for tomcat:8
---> 8973f493aa0a
Step 2/3 : MAINTAINER "shweta"
---> Running in f84d33a29144
Removing intermediate container f84d33a29144
---> d1823a301759
Step 3/3 : COPY ./webapp.war /usr/local/tomcat/webapps
COPY failed: stat /var/lib/docker/tmp/docker-builder241674033/webapp.war: no such file or directory
我webapp.war
在当前目录中创建了一个文件:
touch webapp.war
现在运行docker build
命令:
docker build -f Dockerfile .
输出 :
Sending build context to Docker daemon 749.1kB
Step 1/3 : From tomcat:8
---> 8973f493aa0a
Step 2/3 : MAINTAINER "shweta"
---> Using cache
---> d1823a301759
Step 3/3 : COPY ./webapp.war /usr/local/tomcat/webapps
---> 1f9c0af8b8d3
Successfully built 1f9c0af8b8d3
它建得很好。