正在按照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'.

如何解决?


当前回答

打开PowerShelland并遵循以下说明。 这种类型的错误通常出现在Windows S.O.中 当您使用命令构建时,需要一个选项和路径。

出现这种类型的错误是因为您没有在Dockerfile中指定路径。

试试这个:

C:\Users\Daniele\app> docker build -t friendlyhello C:\Users\Daniele\app\

Friendlyhello是分配给容器的名称 c:\ users \ daniel \app\是包含Dockerfile的路径

如果你想添加一个标签

C:\Users\Daniele\app> docker build -t friendlyhello:3.0 C:\Users\Daniele\app\

其他回答

在我的例子中,我使用了一个破折号(稍微长一点的连字符)符号——在t选项出现问题之前。

docker build –t simple-node .

替换为连字符/减号。

docker build -t simple-node .
#Using a file other than Dockerfile instead.
#Supose my file is `Dockerfile-dev`

docker build -t mytag - < Dockerfile-dev

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

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

Bad:

Sudo docker build -t foo。

好:

Sudo docker build -t foo。

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

从命令运行:

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 .

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

我在管道脚本中使用Docker与Jenkins管道时得到了这个错误。解决方案是在管道脚本中使用以下语法:

docker.build("[my_docker_image_tag]", "-f ./path/to/my/Dockerfile.jvm .")