Bazel创建的Docker映像没有存储库/标记,文件中有奇怪的名称,无法运行

Bazel创建的Docker映像没有存储库/标记,文件中有奇怪的名称,无法运行,docker,bazel,Docker,Bazel,我正在尝试使用Bazel将使用Bazel编译的应用程序打包到Docker映像中 我有一个空的WORKSPACE文件,下面是main.cc文件: #include <stdio.h> int main() { printf("Hello World\n"); } { "bazel/": { "hello_docker": "3d529b3ceeb0d9ef33f6225e655f3f5a0e061888f25cd6a3fac11604778ef6a8" } } 可提

我正在尝试使用Bazel将使用Bazel编译的应用程序打包到Docker映像中

我有一个空的
WORKSPACE
文件,下面是
main.cc
文件:

#include <stdio.h>
int main() { printf("Hello World\n"); }
{
  "bazel/": {
    "hello_docker": "3d529b3ceeb0d9ef33f6225e655f3f5a0e061888f25cd6a3fac11604778ef6a8"
  }
}
可提供要点

当我运行
bazel run:hello
时,我可以看到“hello World”已成功打印。然后我运行
bazel-build:hello_-docker.tar
,在
bazel-bin/hello_-docker.tar
中为docker生成完整的图像。看起来是的

然后我跑:

$ docker load -i bazel-bin/hello_docker.tar
51525b594688: Loading layer [==================================================>] 10.24 kB/10.24 kB
Loaded image ID: sha256:252367f43640968343ecd78b2a3533c8ed99c4be66d73fc3ec6ccb137df19625
然后我列出所有图像:

$ docker images
REPOSITORY                      TAG                 IMAGE ID            CREATED             SIZE
ubuntu                          14.04               b969ab9f929b        3 weeks ago         188 MB
docker/whalesay                 latest              6b362a9f73eb        21 months ago       247 MB
<none>                          <none>              252367f43640        292 years ago       8.048 kB
另一个问题:当我尝试在新容器中运行映像时,它失败了:

$ docker run -t -i 25236
docker: Error response from daemon: oci runtime error: exec: "./hello": stat ./hello: no such file or directory.
我再次查看了生成的
tar
文件,发现这里有一个可执行文件,但出于某种原因它被命名为
o
。另一次尝试和另一个错误:

$ docker run -t -i 25236 ./o
write pipe: bad file descriptor
奇怪的是,如果我将
hello
可执行文件与我自己的
Dockerfile
打包成这样,“hello World”将按预期打印:

FROM ubuntu:14.04
ADD hello .
CMD ./hello
有人能建议如何解决这三个问题中的任何一个吗?我认为它们是互连的,我有错误的构建文件(也许我应该以某种方式指定哪个Linux映像用作基础?)。概述:

  • Bazel生成的图像导入Docker后,不会显示存储库/标记名
  • hello
    文件以
    o
    的名称添加到图像中
  • 即使作为
    o
    运行,停靠的可执行文件也会产生“坏文件描述符”消息
  • 我的软件版本:

    $ bazel version
    Build label: 0.4.4
    Build target: bazel-out/local-fastbuild/bin/src/main/java/com/google/devtools/build/lib/bazel/BazelServer_deploy.jar
    Build time: Wed Feb 1 18:54:21 2017 (1485975261)
    Build timestamp: 1485975261
    Build timestamp as int: 1485975261
    
    $ docker version
    Client:
     Version:      1.12.3
     API version:  1.24
     Go version:   go1.6.2
     Git commit:   6b644ec
     Built:        Mon, 19 Dec 2016 09:20:48 +1300
     OS/Arch:      linux/amd64
    
    Server:
     Version:      1.12.3
     API version:  1.24
     Go version:   go1.6.2
     Git commit:   6b644ec
     Built:        Mon, 19 Dec 2016 09:20:48 +1300
     OS/Arch:      linux/amd64
    

    嗯,看起来第二个问题是a,第三个问题的症状类似于用
    从头开始构建图像,而不是从ubuntu:14.04
    创建图像。我目前的假设是,Bazel不允许使用任何非Bazel创建的图像作为基础,包括来自Docker Hub的图像,如
    ubuntu:14.04
    $ bazel version
    Build label: 0.4.4
    Build target: bazel-out/local-fastbuild/bin/src/main/java/com/google/devtools/build/lib/bazel/BazelServer_deploy.jar
    Build time: Wed Feb 1 18:54:21 2017 (1485975261)
    Build timestamp: 1485975261
    Build timestamp as int: 1485975261
    
    $ docker version
    Client:
     Version:      1.12.3
     API version:  1.24
     Go version:   go1.6.2
     Git commit:   6b644ec
     Built:        Mon, 19 Dec 2016 09:20:48 +1300
     OS/Arch:      linux/amd64
    
    Server:
     Version:      1.12.3
     API version:  1.24
     Go version:   go1.6.2
     Git commit:   6b644ec
     Built:        Mon, 19 Dec 2016 09:20:48 +1300
     OS/Arch:      linux/amd64