我今天刚刚下载了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中。不是Dockerfile,因为在打开文件命令时:

notepad Dockerfile

(由于写入了文本文件,因此无法构建该文件。)

要构建文件,运行:

notepad Dockerfile

现在运行:

docker build -t docker-whale .

确保您在Dockerfile的当前目录中。

其他回答

错误消息具有误导性

这个问题实际上与符号链接无关。 通常,问题只是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.

如果我们的环境中有多个Docker文件,那么只有Dockerfile不能满足我们的需求。

docker build -t ihub -f Dockerfile.ihub .

因此,使用file (-f参数)命令指定docker文件(Dockerfile.ihub)。

这只是因为记事本在Dockerfile末尾添加了“。txt”。

在WSL中,路径转换似乎存在问题。Dockerfile在Ubuntu中的位置(我运行Docker的位置和Dockerfile所在的位置)是“/home/sxw455/App1”,但这两个命令都不起作用:

$ pwd

/home/sxw455/App1

$ ll

total 4
drwxrwxrwx 0 sxw455 sxw455 4096 Dec 11 19:28 ./
drwxr-xr-x 0 sxw455 sxw455 4096 Dec 11 19:25 ../
-rwxrwxrwx 1 sxw455 sxw455  531 Dec 11 19:26 Dockerfile*
-rwxrwxrwx 1 sxw455 sxw455  666 Dec 11 19:28 app.py*
-rwxrwxrwx 1 sxw455 sxw455   12 Dec 11 19:27 requirements.txt*

$ docker build -t friendlyhello .

unable to prepare context: unable to evaluate symlinks in Dockerfile path: GetFileAttributesEx C:\Windows\System32\Dockerfile: The system cannot find the file specified.

$ docker build -t friendlyhello "/home/sxw455/App1"
unable to prepare context: path "/home/sxw455/App1" not found

但在Windows中,实际路径是:

C:\Users\sxw455\AppData\Local\Packages\CanonicalGroupLimited.Ubuntu18.04onWindows_79rhkp1fndgsc\LocalState\rootfs\home\sxw455\App1

所以我必须这样做(即使我从Bash运行它):

$ docker build -t friendlyhello

"C:\Users\sxw455\AppData\Local\Packages\CanonicalGroupLimited.Ubuntu18.04onWindows_79rhkp1fndgsc\LocalState\rootfs\home\sxw455\App1"

Sending build context to Docker daemon   5.12kB
Step 1/7 : FROM python:2.7-slim
 ---> 0dc3d8d47241
Step 2/7 : WORKDIR /app
 ---> Using cache
 ---> f739aa02ce04
Step 3/7 : COPY . /app
 ---> Using cache
 ---> 88686c524ae9
Step 4/7 : RUN pip install --trusted-host pypi.python.org -r requirements.txt
 ---> Using cache
 ---> b95f02b14f78
Step 5/7 : EXPOSE 80
 ---> Using cache
 ---> 0924dbc3f695
Step 6/7 : ENV NAME World
 ---> Using cache
 ---> 85c145785b87
Step 7/7 : CMD ["python", "app.py"]
 ---> Using cache
 ---> c2e43b7f0d4a
Successfully built c2e43b7f0d4a
Successfully tagged friendlyhello:latest
SECURITY WARNING: You are building a Docker image from Windows against a non-Windows Docker host. All files and directories added to build context will have '-rwxr-xr-x' permissions. It is recommended to double check and reset permissions for sensitive files and directories.

在最初的安装过程中,我在环境变量方面遇到了类似的问题,并遵循了一些建议,建议安装Windows DockerCE并破解环境变量,而不是安装Ubuntu DockerCE,因为(我希望我没记错)WSL没有完全实现systemctl。一旦Windows Docker CE安装完成并设置好环境变量,Docker就可以在WSL/Ubuntu下正常工作了。

我把我的文件命名为dockerfile而不是dockerfile(大写),一旦我改变了这个名字,它就开始处理我的“dockerfile”。