我今天刚刚下载了Windows 10 64位的Docker工具箱。我正在看教程。当我试图使用Dockerfile构建一个映像时,我收到以下错误。

步骤:

启动Docker快速入门终端。 Testdocker创建后。 准备Dockerfile文档在“建立你自己的形象”网页链接 运行以下命令

Docker build -t Docker -whale。

错误:$ docker build -t docker-whale。

unable to prepare context: unable to evaluate symlinks in Dockerfile path: GetFileAttributesEx C:\Users\Villanueva\Test\testdocker\Dockerfile:系统找不到指定的文件。

顺便说一句:我尝试了提到的几个选项@ https://github.com/docker/docker/issues/14339

docker info

输出:

Containers: 4
 Running: 0
 Paused: 0
 Stopped: 4
Images: 2
Server Version: 1.10.1
Storage Driver: aufs
 Root Dir: /mnt/sda1/var/lib/docker/aufs
 Backing Filesystem: extfs
 Dirs: 20
 Dirperm1 Supported: true
Execution Driver: native-0.2
Logging Driver: json-file
Plugins:
 Volume: local
 Network: bridge null host
Kernel Version: 4.1.17-boot2docker
Operating System: Boot2Docker 1.10.1 (TCL 6.4.1); master : b03e158 - Thu Feb 11 22:34:01 UTC 2016
OSType: linux
Architecture: x86_64
CPUs: 1
Total Memory: 996.2 MiB
Name: default
ID: C7DS:CIAJ:FTSN:PCGD:ZW25:MQNG:H3HK:KRJL:G6FC:VPRW:SEWW:KP7B
Debug mode (server): true
 File Descriptors: 32
 Goroutines: 44
 System Time: 2016-02-19T17:37:37.706076803Z
 EventsListeners: 0
 Init SHA1:
 Init Path: /usr/local/bin/docker
 Docker Root Dir: /mnt/sda1/var/lib/docker
Labels:
 provider=virtualbox

当前回答

最重要的是,确保文件名为Dockerfile。如果你用另一个名字是行不通的(至少对我来说不是)。

此外,如果您在Dockerfile所在的同一目录中,请使用.,即,

docker build -t Myubuntu1:v1。

或者使用绝对路径,即,

docker build -t Myubuntu1:v1 /Users/<username>/Desktop/ docker . txt

其他回答

该错误意味着docker构建使用了一个不正确输入的PATH | URL,或者在当前目录中无法找到Dockerfile。此外,确保从集成终端(例如IDE或文本编辑器中的bash)运行该命令时,您具有管理权限。 如果你可以用pwd从你的终端检查路径(在bash shell中或在windows上使用简单的cli时使用dir),并复制你想要构建图像的确切路径,那就最好了。

docker编译C:\windows\your_amazing_directory

Docker build——help还将向您展示在格式错误或非法命令的情况下可用的选项。

此问题与DockerFile创建过程有关。

为了工作,打开cmd, cd到感兴趣的目录,输入:

abc>DockerFile

这将在您的文件夹中创建一个名为DockerFile的文件。

现在类型:

notepad DockerFile

这将在记事本中打开DockerFile文件,你必须复制/粘贴提供的标准代码。

保存文件,现在,最后,用Docker输入构建您的映像:

docker build -t docker-whale .

这对我很有用。

构建dockerfile的两种方法:

你可以决定不指定要构建的文件名,而只是指定一个路径来构建它(这样做的话,文件名必须是Dockerfile,不附加扩展名,例如:docker build -t docker-whale:tag path/to/Dockerfile

or

你可以用-f指定一个文件,不管你决定使用什么扩展名(在合理的范围内。txt, .dockerfile, .dockerfile等.),例如docker build -t docker-whale:tag /path/to/file -f docker-whale.dockerfile。

我用Visual Studio 2017 Docker支持工具创建了DockerFile,也出现了同样的错误。

过了一会儿,我意识到我不在包含Dockerfile的正确目录(~\source\repos\DockerWebApplication\)。我cd到项目内部的正确文件(~/source/repos/DockerWebApplication/DockerWebApplication),并成功创建了Docker映像。

错误消息具有误导性

这个问题实际上与符号链接无关。 通常,问题只是Docker找不到描述构建的Dockerfile。

典型原因如下:

Dockerfile has wrong name. It must be called Dockerfile. If it is called, for instance, dockerfile, .Dockerfile, Dockerfile.txt, or other, it will not be found. Dockerfile is not in context. If you say docker build contextdir, the Dockerfile must be at contextdir/Dockerfile. If you have it in, say, ./Dockerfile instead, it will not be found. Dockerfile does not exist at all. Does it sound silly? Well, I got the above error message from my GitLab CI after I had written a nice Dockerfile, but I had forgotten to check it in. Silly? Sure. Unlikely? No.