Docker Hello world - oci运行时错误



我试图理解Docker,我有一个非常简单的Dockerfile在我的OSX上的~/dockerfiles/test

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

我为什么会面临这个问题?

您从SCRATCH(空图像)开始,您正在使用cat,这不是shell内置的

cat需要/bin/sh运行(它将fork进程并加载动态库)


注意:默认情况下,ENTRYPOINT/bin/sh -c,但是文档"使用scratch创建简单的基础图像"显示ENTRYPOINT对于scratch图像是空的。

正如BMitch下面评论的:

快速解决问题的方法是将其更改为FROM debian:latest甚至FROM busybox:latest,如果大小重要

目前使用的图像是alpine

FROM alpine:3.4

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

相关内容

最新更新