正在按照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 file和Dockerfile的文件构建docker映像。它有一组你在docker容器中需要的命令/指令。 下面的命令创建带有标签latest的图像,Dockerfile应该显示在该位置(。表示当前目录)

docker build . -t <image_name>:latest

如果Dockerfile不是默认文件名(Dockerfile),可以通过-f指定Dockerfile。 Sameple Docker文件内容。

FROM busybox
RUN echo "hello world"

其他回答

从命令运行:

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 .

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

你需要在结尾加一个DOT…


例如:

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

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

#Using a file other than Dockerfile instead.
#Supose my file is `Dockerfile-dev`

docker build -t mytag - < Dockerfile-dev

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

docker build –t simple-node .

替换为连字符/减号。

docker build -t simple-node .

Docker构建命令格式

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

试试这个:

$ docker build -t friendlyhello:latest -f C:\\TestDockerApp\\Dockerfile.txt

Friendlyhello是你分配给你的容器的名称,并添加版本,只需使用:latest

- f C: \ TestDockerApp \ Dockerfile.txt -你想添加一个标签,因为构建命令需要一个参数或标签 DockerFile是一个文本文档,所以明确添加扩展名。txt

**尝试以下格式:

$ docker build -t friendlyhello:latest -f C:\\TestDockerApp\\Dockerfile.txt .**