正在按照docker网站上的说明构建docker映像。

https://docs.docker.com/examples/running_redis_service/

这是我得到的错误将遵循文档上的说明,并使用这个Dockerfile

FROM        ubuntu:14.04
RUN         apt-get update && apt-get install -y redis-server
EXPOSE      6379
ENTRYPOINT  ["/usr/bin/redis-server"]


sudo docker build -t myrepo/redis
docker: "build" requires 1 argument. See 'docker build --help'.

如何解决?


当前回答

下面的命令对我有用。Docker文件放在my-app-master文件夹中。

docker build -f my-app-master/Dockerfile -t my-app-master

其他回答

你需要在结尾加一个DOT…


例如:

$ docker build -t <your username>/node-web-app .

它有点隐蔽,但如果你注意。最后……

从命令运行:

sudo docker build -t myrepo/redis

没有传递给docker build命令的“参数”,只有一个标志-t和该标志的值。在docker解析完命令的所有标志后,在运行构建时应该会留下一个参数。

这个参数就是构建上下文。标准命令包含上下文的尾随点:

sudo docker build -t myrepo/redis .

构建上下文是什么?

Every docker build sends a directory to the build server. Docker is a client/server application, and the build runs on the server which isn't necessarily where the docker command is run. Docker uses the build context as the source for files used in COPY and ADD steps. When you are in the current directory to run the build, you would pass a . for the context, aka the current directory. You could pass a completely different directory, even a git repo, and docker will perform the build using that as the context, e.g.:

docker build -t sudobmitch/base:alpine --target alpine-base \
  'https://github.com/sudo-bmitch/docker-base.git#main'

有关构建命令的这些选项的更多详细信息,请参阅docker构建文档。

如果你加入一个论点呢?

如果包含构建上下文的值(通常是.),但仍然看到此错误消息,则可能传递了多个参数。通常情况下,这是由于未能解析标志,或传递了一个不带引号的空格字符串。docker看到多个参数的可能原因包括:

路径或参数周围缺少引号(注意使用可能含有空格的变量) 命令中不正确的破折号:请确保手动键入这些破折号,而不是复制和粘贴 不正确的引号:智能引号不能在命令行上工作,手动输入它们,而不是复制和粘贴。 不是空白的空格,或者看起来不是空格。

大多数这些错误都是由于打字错误或从源代码复制粘贴来修改文本,使其看起来更漂亮,使其无法用作命令。

如何找出CLI错误在哪里?

我调试这个最简单的方法是,在没有任何其他标志的情况下运行命令:

docker build .

一旦它起作用,再添加标记,直到你得到错误,然后你就会知道哪个标记坏了,需要修复/添加引号或纠正破折号等。

在我的例子中,这个错误发生在Gitlab CI管道中,当我传递多个Gitlab env变量到docker build时,使用——build-arg标志。

结果发现其中一个变量中有空格,这导致了错误。很难找到它,因为管道日志只显示$VARIABLE_NAME。

确保引用环境变量,以便正确处理空格。

改变:

--build-arg VARIABLE_NAME=$VARIABLE_NAME

to:

--build-arg VARIABLE_NAME="$VARIABLE_NAME"

您需要添加一个点,这意味着使用本地目录中的Dockerfile。

例如:

Docker build -t mytag。

这意味着你在本地目录中使用Dockerfile,如果你使用docker 1.5,你可以在其他地方指定Dockerfile。从docker build的帮助输出中提取:

-f,——file="" Dockerfile的名称(默认为'Dockerfile')

是否从其他地方(网页或其他文件)复制了构建命令?试着从头输入。

我从AWS教程中复制了一个构建命令,并将其粘贴到我的终端,并得到了这个错误。我都快疯了。在用手输入之后,它工作了!仔细观察我之前失败的命令,我注意到“破折号”字符是不同的,它比我自己用“减号/破折号”键输入的字符更细,更长。

Bad:

Sudo docker build -t foo。

好:

Sudo docker build -t foo。

你能看出区别吗?复制粘贴很难。