我喜欢我的所有微服务都可以使用多阶段构建作为docker build .
构建的想法。
但是,我也很想在构建后通过快速docker run
和curl /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