Docker 构建找不到缓存键



项目树

- dockerable
-- dock
--- Dockerfile
-- index.html

我在index.html上做了一个简单的网站:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>my journay to dockerising</title>
</head>
<body>
<p>this is an education project by me</p>
</body>
</html>

并尝试在Dockerfile中使用apache2容器化:

FROM httpd:2.4.57
WORKDIR /Users/asklipios/Desktop/dockerable
COPY /Users/asklipios/Desktop/dockerable/index.html /
COPY . . 
ENV port = 5000
EXPOSE 5000
CMD [ "httdp" ,"start"]

但是当我运行:docker run -t asklipios/exmple:1.0 /Users/asklipios/Desktop/dockerable它给了我这个:

[+] Building 1.2s (7/8)                             
=> [internal] load build definition from Doc  0.1s
=> => transferring dockerfile: 318B           0.0s
=> [internal] load .dockerignore              0.1s
=> => transferring context: 2B                0.0s
=> [internal] load metadata for docker.io/li  0.8s
=> [internal] load build context              0.1s
=> => transferring context: 313B              0.0s
=> CANCELED [1/4] FROM docker.io/library/htt  0.1s
=> => resolve docker.io/library/httpd:2.4.57  0.1s
=> => sha256:a86b8ccb1e65a55 1.86kB / 1.86kB  0.0s
=> CACHED [2/4] WORKDIR /Users/asklipios/Des  0.0s
=> ERROR [3/4] COPY /Users/asklipios/Desktop  0.0s
------
> [3/4] COPY /Users/asklipios/Desktop/dockerable/index.html /:
------
failed to compute cache key: "/Users/asklipios/Desktop/dockerable/index.html" not found: not found
  1. 我尝试重拉http图像
  2. 我试着用谷歌搜索
  3. 我搜索了stackoverflow

不能在dockerfile中使用绝对路径;dockerfile中的源路径是相对于Docker构建上下文的根目录的。

根据图片的文档,你应该把你的HTML放在/usr/local/apache2/htdocs/中,所以dockerfile应该是

FROM httpd:2.4.57
COPY ./index.html /usr/local/apache2/htdocs/

和你的命令,假设你当前的工作目录是index.html所在的地方,应该是

docker build -f dock/Dockerfile .

所以它使用当前工作目录作为Docker构建上下文,dock/Dockerfile作为dockerfile。

相关内容

  • 没有找到相关文章

最新更新