Docker Hello Wold - oci运行时错误

时间:2016-09-08 07:22:20

标签: macos docker

我正在尝试了解Docker,我在OSX上的~/dockerfiles/test处有一个非常简单的 Dockerfile

FROM scratch
RUN echo "Hello world" > ~/helloworld.txt
CMD ["cat", "~/helloworld.txt"]

当我尝试为此文件构建图像时,如

docker build -t simple .

我在构建过程中遇到错误。

错误输出

Sending build context to Docker daemon 2.048 kB
Step 1 : FROM scratch
 ---> 
Step 2 : RUN echo "Hello world" > ~/helloworld.txt
 ---> Running in fc772fd39d45
oci runtime error: exec: "/bin/sh": stat /bin/sh: no such file or directory

关于我为什么要面对这个问题的任何指示?

1 个答案:

答案 0 :(得分:2)

您开始from SCRATCH(空图片),您正在使用cat, which is not a shell built-in

cat需要运行/bin/sh(它会分叉进程并加载动态库)

注意:默认情况下,ENTRYPOINT/bin/sh -c,但文档" Creating a simple base image using scratch"显示临时图像的ENTRYPOINT为空。

正如BMitch评论below

  

如果尺寸重要,问题的快速解决方法就会从FROM debian:latest甚至FROM busybox:latest变为

目前使用的图片是 alpine

FROM alpine:3.4

图像只有5 MB,并且可以访问比其他基于BusyBox的图像更完整的软件包存储库。