Docker可以在多阶段构建中测试映像吗?

时间:2019-05-13 17:31:49

标签: docker dockerfile

我喜欢我的所有微服务都可以使用多阶段构建作为docker build .构建的想法。

但是,我也很想在构建后通过快速docker runcurl /endpoint进行烟雾测试,以检查应用程序是否成功。

我想知道是否有任何方法可以将其包装在多级Dockerfile中?我已经解决了不必通过粘贴尾随--target来指定正确的FROM app的问题。

这就是我想要做的:

FROM alpine:latest as builder
WORKDIR /tmp/
RUN echo "#!/bin/sh" > helloworld.sh && \
    echo "echo hello world" >> helloworld.sh && \
    chmod oug+x helloworld.sh

FROM alpine:latest as app
WORKDIR /root/
COPY --from=builder /tmp/helloworld.sh .
CMD ["./helloworld.sh"]

FROM docker:latest as tester
# Fails - no docker daemon - impossible to mount /var/run/docker.sock during build ?
RUN output=`docker run --rm app`; if [ "$output" == 'hello world' ]; then exit 0; else exit 1; fi

FROM app # means the second image is the default output

0 个答案:

没有答案
相关问题