[英]Dockerfile COPY command stops working when I change the FROM image
I have two custom images.我有两个自定义图像。 One is for developing websites using next.js and the other is to develop APIs.
一个是用next.js开发网站,一个是开发API。
My company/site
image is like:我的
company/site
形象是这样的:
FROM node:lts-bullseye-slim
# the rest of it
And my company/api
image is like:我的
company/api
图像是这样的:
ARG VARIANT="6.0-bullseye-slim"
FROM mcr.microsoft.com/vscode/devcontainers/dotnet:${VARIANT}
# the rest of it
The problem is that, the COPY
commands works when I use company/api
as my FROM
image, but fails when I use company/site
.问题是,当我使用
company/api
作为我的FROM
图像时, COPY
命令有效,但当我使用company/site
时失败。
In other words, this works:换句话说,这有效:
FROM company/api
COPY . .
RUN /buildScript.sh
But for the same directory, the same context, the same everything, this fails:但是对于相同的目录,相同的上下文,相同的一切,这失败了:
FROM compnay/site
COPY . .
RUN /buildScript.sh
In other words, COPY
copies no file to the image.换句话说,
COPY
不向图像复制任何文件。 Everything is the same.一切都一样。 There is no
.dockerignore
file.没有
.dockerignore
文件。 The same directory, the same context, the same syntax docker build -t company/api-or-site.
相同的目录,相同的上下文,相同的语法
docker build -t company/api-or-site.
The only thing that causes this fail, is changing the base image.导致此失败的唯一原因是更改基本图像。
What can cause this error?什么会导致此错误? How can I debug this?
我该如何调试呢?
After spending days on this, I finally realized what the problem was.花了几天时间,我终于意识到问题出在哪里了。
When you create a custom image using a Dockerfile
, if you use the WORKDIR
command, then that would be the .
当您使用
Dockerfile
创建自定义图像时,如果您使用WORKDIR
命令,那么它将是.
in your future COPY
commands.在您以后的
COPY
命令中。
Consider the following image:考虑下图:
FROM node:lts-bullseye-slim
# Your specific commands
WORKDIR /project
Let's say you build this image and tag it company/node
.假设您构建此映像并将其标记为
company/node
。
Now if you want to use it as the base image for another image, and COPY. .
现在,如果你想将它用作另一个图像的基础图像,然后
COPY. .
COPY. .
files, then those files would be copied to the /project
directory.文件,那么这些文件将被复制到
/project
目录。
FROM company/node
COPY . . # here, the second dot means the relative path inside the company/node image
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.