docker build找不到缓存键

toiithl6  于 2023-04-20  发布在  Docker
关注(0)|答案(1)|浏览(111)

项目树

- 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.我试着重拉了一下https镜像
1.我试着谷歌了一下
1.我在stackoverflow上搜索过

t8e9dugd

t8e9dugd1#

你不能在dockerfile中使用绝对路径;dockerfile中的源路径相对于the root of the Docker build context
根据to the docs for the image,您应该将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。

相关问题