2014-09-18 62 views
3

我在玩Google's Dart docker image。我正在尝试构建一个侦听端口80的Hello World应用程序。我在Azure上的Ubuntu Server 14上运行它。为什么Docker不向我的容器添加文件?

如果我运行google/dart-hello,这一切工作正常,我可以在8080端口上

连接google/dart-hello图像是基于google/dart-runtime形象,这是反过来,基于google/dart上。基本图像添加了Dart; google/dart-runtime添加了Dockerfile,该Dockerfile预计执行bin/server.dart并显示端口8080,google/dart-hello提供bin/server.dart(和pubspec.yaml)以使其工作。因为它不包含bin/server.dartpubspec.yaml,所以它本身没有用处。

所以,google/dart-runtime是一个很好的基础,如果你的服务器是在bin/server.dart要在8080端口上监听,因为我想在端口80听,我使用的google/dart图像为基础,希望能壁球什么在google/dart-runtimegoogle/dart-hello到我的容器,而是改为端口80

你可以找到三个谷歌图像这里的回购来源:

所以,我已经采取了从google/dart-runtime的Dockerfile和google/dart-hello的文件,所以我有以下几点:

FROM google/dart 

WORKDIR /app 
ONBUILD ADD pubspec.yaml /app/ 
ONBUILD ADD pubspec.lock /app/ 
ONBUILD RUN pub get 
ONBUILD ADD . /app 
ONBUILD RUN pub get 

CMD [] 
ENTRYPOINT ["/usr/bin/dart", "/app/bin/server.dart"] 
EXPOSE 80 

在同目录作为这个Dockerfile,我有以下文件:

  • 斌/ server.dart
  • pubspec.yaml
  • pubspec.lock

我正在创建的图像用:

sudo docker build --no-cache -t dart-test . 

而这里的输出:

[email protected]:~/dart_test$ sudo docker build --no-cache -t dart-test . 
Sending build context to Docker daemon 5.632 kB 
Sending build context to Docker daemon 
Step 0 : FROM google/dart 
---> cd92c7fff717 
Step 1 : WORKDIR /app 
---> Running in d163d2597eba 
---> 2802d6769b76 
Removing intermediate container d163d2597eba 
Step 2 : ONBUILD ADD pubspec.yaml /app/ 
---> Running in 7b8be2a481c2 
---> 096cbe12a2cd 
Removing intermediate container 7b8be2a481c2 
Step 3 : ONBUILD ADD pubspec.lock /app/ 
---> Running in 6ae0243b0dee 
---> 80f20ebafa87 
Removing intermediate container 6ae0243b0dee 
Step 4 : ONBUILD RUN pub get 
---> Running in 621d4ce5c7f1 
---> 89a509d41b11 
Removing intermediate container 621d4ce5c7f1 
Step 5 : ONBUILD ADD . /app 
---> Running in 4de26a33487f 
---> b69c65f12441 
Removing intermediate container 4de26a33487f 
Step 6 : ONBUILD RUN pub get 
---> Running in f7cc689f6f81 
---> 2ccc79ea6d04 
Removing intermediate container f7cc689f6f81 
Step 7 : CMD [] 
---> Running in 10bd31eb6679 
---> f828267f00b5 
Removing intermediate container 10bd31eb6679 
Step 8 : ENTRYPOINT ["/usr/bin/dart", "/app/bin/server.dart"] 
---> Running in 013d3ca0f25d 
---> a63b59f9fd05 
Removing intermediate container 013d3ca0f25d 
Step 9 : EXPOSE 80 
---> Running in 4301c572e598 
---> 75a4317c135c 
Removing intermediate container 4301c572e598 
Successfully built 75a4317c135c 

但是,如果我尝试运行此操作(使用sudo docker run --rm -i -t dart-test),则会出现以下错误:

[email protected]:~/dart_test$ sudo docker run -i -t --rm dart-test 
Unhandled exception: 
Uncaught Error: FileSystemException: Cannot open file, path = '/app/bin/server.dart' (OS Error: No such file or directory, errno = 2) 

如果我替换Dockerfile的dart执行与/bin/bash代替,后来当我建立和运行,我得到投入bash/app/但该文件夹是

我试过这个0.9(?)版本和1。2(其中一个来自apt-get docker.io,另一个来自Docker网站上的更多参与指令),因为我注意到在发行说明中提到了ADD修复。两者都是一样的。

我可以在网上找到大量的信息,人们经常将Dockerfile管入STDIN,这意味着没有context,但是您可以在我的输出中看到正在发送5KB数据;虽然有可能这只是Dockerfile,我猜想没有其他的东西?他们是在同一个目录,这里有一个清单:当您创建一个稍后将由另一Dockerfile使用的基本映像(见documentation

[email protected]:~/dart_test$ dir 
bin Dockerfile pubspec.lock pubspec.yaml 

回答

7

ONBUILD指令时才有用。

在这里,因为你写的最后Dockerfile,你只需要删除ONBUILD指令(但保留原始指令ADDRUN等)。

+1

哦,那人一点都不迷惑! :)现在就试试吧! – 2014-09-18 17:51:32

+0

太棒了;发现!谢谢:) – 2014-09-18 17:57:19

+1

对于所有似乎包含这些添加的输出(并创建临时图像?),我有点困惑,如果它没有真的做任何事情! – 2014-09-18 18:05:16

3

在您的Dockerfile中,您需要从指示中删除ONBUILD前缀。 ONBUILD前缀是推迟执行某些指令的一种方式,直到该图像被另一个Dockerfile引用为止。这些指令被存储为您创建的图像的元数据的一部分,但指令本身不会被执行,直到该图像在另一DockerfileFROM字段中被引用。

你真正想要的是这样的:

FROM google/dart 

WORKDIR /app 
ADD pubspec.yaml /app/ 
ADD pubspec.lock /app/ 
RUN pub get 
ADD . /app 
RUN pub get 

CMD [] 
ENTRYPOINT ["/usr/bin/dart", "/app/bin/server.dart"] 
EXPOSE 80 
3

泊坞窗图像谷歌/镖运行时的目的是为您的飞镖服务器应用程序的基本图像。因此,在你的项目时将基本映像中运行docker buildONBUILD命令将被执行的Dockerfile刚才应该包含以下内容

FROM google/dart-runtime 

的。

如果你看Dockerfile对于google/dart-hello你会看到它只有一条线。

相关问题