gpt4 book ai didi

Error response from daemon: No build stage in current context(来自后台进程的错误响应:当前上下文中没有生成阶段)

转载 作者:bug小助手 更新时间:2023-10-25 21:48:13 29 4
gpt4 key购买 nike



I was trying to run a container with kvm, using the code I found here: https://github.com/jessfraz/dockerfiles/tree/master/kvm
I created a new directory, cd'd into it and created the dockerfile and start.sh files.
When I gave order to build, it outputted the following error message:

我试图使用kvm运行容器,使用我在这里找到的代码:https://github.com/jessfraz/dockerfiles/tree/master/kvm我创建了一个新目录,cd进入其中,并创建了dockerfile和start.sh文件。当我发出构建命令时,它输出了以下错误消息:


Sending build context to Docker daemon  3.584kB
Error response from daemon: No build stage in current context

I have no idea what this means and I couldn't Google an answer.
Any help?

我不知道这意味着什么,我也无法在谷歌上搜索到答案。有什么帮助吗?


更多回答
优秀答案推荐

Does your dockerfile have a: FROM repo/image

您的dockerfile是否有:from repo/Image



As the first line? I got this error when I forgot to specify the docker image that I was building from.

作为第一行吗?当我忘记指定要从其构建的docker映像时,我收到了这个错误。



Even if you're building a "source image" you still need to specify FROM scratch as the first line of the dockerfile.

即使您正在构建一个“源映像”,您仍然需要从头开始指定为dockerfile的第一行。



This usually happens because of the text that is written before the FROM command. Try removing the comments in your dockerfile and build again.

这通常是由于在from命令之前写入的文本所致。尝试删除您的dockerfile中的注释,然后重新构建。



For reference https://github.com/moby/buildkit/issues/164

供参考https://github.com/moby/buildkit/issues/164



This message appears when you declare an environment variable (ENV) before declaring FROM.

在从声明之前声明环境变量(ENV)时,会出现此消息。



For example:

例如:



# Define variables.
ARG PORT
ENV SERVER_PORT=$PORT

# Install minimal Python 3.
FROM python:3.7-alpine

# Install Python requirements.
COPY requirements.txt /
RUN pip install -r /requirements.txt

# Copy app source code.
COPY src/ /app
...


To resolve this, swap the declarations so that any environment variables are set after FROM.

要解决此问题,请交换声明,以便在From之后设置所有环境变量。



# Install minimal Python 3.
FROM python:3.7-alpine

# Define variables.
ARG PORT
ENV SERVER_PORT=${PORT}

# Install Python requirements.
COPY requirements.txt /
RUN pip install -r /requirements.txt

# Copy app source code.
COPY src/ /app
...


According to the documentation on docs.docker.com, the first non-comment line of your Dockerfile must be the FROM line. To quote the docs:

根据docs.docker.com上的文档,Dockerfile的第一个非注释行必须是From行。引用这些文件:




The FROM instruction initializes a new build stage and sets the Base Image for subsequent instructions. As such, a valid Dockerfile must start with a FROM instruction.




If you are still using the deprecated MAINTAINER keyword, you must have the FROM command as the first command in the Dockerfile:

如果您仍在使用过时的Maintainer关键字,则必须将FROM命令作为Dockerfile中的第一个命令:


BAD:

不好的:


MAINTAINER your name "[email protected]"
FROM dockerimagename

GOOD:

好:


FROM dockerimagename
MAINTAINER your name "[email protected]"


The problem is resolved.
When I went to dockerfile to edit the code I noticed that I accidentally uncommented the first line. Stupid mistake, I know.
Thank you both for the help.

问题解决了。当我转到dockerfile编辑代码时,我注意到我意外地取消了第一行的注释。我知道这是个愚蠢的错误。谢谢你们两位的帮助。



It was my case because I had ENV specified before FROM and as already mentioned, the FROM should be the first expression in your Dockerfile.

这是我的例子,因为我在From之前指定了ENV,并且正如前面提到的,From应该是Dockerfile中的第一个表达式。


BUT


Since this PR https://github.com/moby/moby/pull/31352 you can specify ARG before FROM which might be suitable alternative for you.

由于此PR https://github.com/moby/moby/pull/31352,您可以指定arg之前,从哪个可能是适合您的替代。


So I've changed

所以我改变了


ENV MY_VAR 1
FROM ...

to


ARG MY_VAR=1
FROM ...



BTW You can read about ARG vs ENV difference here https://vsupalov.com/docker-arg-vs-env/

顺便说一句,你可以在这里阅读关于ARG和ENV的区别,https://vsupalov.com/docker-arg-vs-env/



I do not think that this is your case, but it might help someone else with that error.

我不认为这是你的情况,但它可能会帮助其他人犯下那个错误。



  1. My Dockerfile ran without that error.

  2. I added "FROM vcatechnology/linux-mint:18.2" to the start of the Dockerfile, no error either.

  3. After deleting that FROM statement again, it was still searching for it, causing this error.

  4. I could only get rid of the error by adding the FROM statement again.


Thus, this error can simply appear if you have used a Dockerfile starting with a FROM statement and if you then drop that FROM statement again.

因此,如果您使用了以From语句开头的Dockerfile,然后再次删除该From语句,则可能会出现此错误。



I removed all the comments in the Dockerfile and it worked just fine

我删除了文档文件中的所有注释,它工作得很好



In my case, I changed RUN to FROM.

在我的例子中,我将Run改为From。


Old Dockerfile:

旧文档文件:


RUN php:8-apache

COPY /src var/www/html/

ENV APACHE_DOCUMENT_ROOT ./src/public/

RUN sed -ri -e 's!/var/www/html!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/sites-available/*.conf

RUN sed -ri -e 's!/var/www/!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/apache2.conf /etc/apache2/conf-available/*.conf

EXPOSE 80

New Dockerfile:

新文档文件:


FROM php:8-apache

COPY /src var/www/html/

ENV APACHE_DOCUMENT_ROOT ./src/public/

RUN sed -ri -e 's!/var/www/html!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/sites-available/*.conf

RUN sed -ri -e 's!/var/www/!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/apache2.conf /etc/apache2/conf-available/*.conf

EXPOSE 80

更多回答

I had this problem because I was setting ENV for the debian frontend before the FROM command. Thanks!

我遇到这个问题是因为在使用from命令之前,我为Debian前端设置了ENV。谢谢!

@adamconkey there's a special case where you're allowed to have ARG before a FROM. That's the only thing that's allowed to be before FROM. Here's some more information about that: docs.docker.com/engine/reference/builder/…

@adamconkey有一个特殊的情况,你可以在FORM之前使用ARG。这是唯一被允许在离开之前的东西。以下是有关这方面的更多信息:docs.docker.com/Engine/Reference/Builder/…

It's not necessarily the FIRST line. It's just got to be the first non-comment line. Check my answer for a link to the official documentation with an explanation.

这不一定是第一行。它只是必须是第一个非注释行。请查看我的回答,以获得官方文档的链接和解释。

@NoBrainer In computer programming, the term "first line" almost always refers to the first non-comment line.

在计算机编程中,术语“第一行”几乎总是指第一个非注释行。

It can also happen if you have more than 1 ARG before the first FROM

如果您在第一个参数之前有一个以上的参数,也可能会发生这种情况

This was my issue exactly, for some reason even the stuff I had commented out was causing it to throw this error. I removed it all and works fine now.

这正是我的问题,出于某种原因,甚至我注释掉的东西都导致它抛出这个错误。我把它都拿掉了,现在运行得很好。

Comments haven't caused me any issues. Check my answer for a link to the official documentation with an explanation.

评论没有给我带来任何问题。请查看我的回答,以获得官方文档的链接和解释。

use either FROM anyBaseImage or use FROM scratch

从任何BaseImage使用或从头开始使用

BTW note that the MAINTAINER keyword is deprecated since years.

顺便说一句,Maintainer关键字多年来一直不受欢迎。

@ValerioBozz, thank you for this note. would you suggest to add a note regarding deprecation and keep this for legacy code or shall we simply drop the answer? I think we can delete this :)

@ValerioBozz,谢谢你的这封信。您是否建议添加关于弃用的注释,并将其保留为遗留代码,或者我们是否应该简单地放弃答案?我认为我们可以删除以下内容:)

@Curious_Watcher I tried to edit the answer to put this note that may be still useful on old versions of Docker.

@Curious_Watcher我试图编辑答案,将这条注释放在旧版本的Docker上可能仍然有用。

Hi @Ivandez. The RUN has no sense with an image argument as far as i know. It's very difficult to pretend that the original questioner had your same problem.

嗨@Ivandez。据我所知,这场竞选与形象论据毫无意义。很难假装原来的提问者和你有同样的问题。

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com