以golang项目为例,Dockerfile在最上层目录,即与main.go在同一目录
FROM golang AS build
ENV CGO_ENABLED=0
ENV GOPROXY=https://goproxy.cn
ENV GO111MODULE=on
RUN mkdir /go/src/myapp
COPY ./ /go/src/myapp/
WORKDIR /go/src/myapp
RUN go build -o /tmp/myapp
FROM alpine
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories
RUN apk add openssh bash --no-cache \
&& sed -i s/"# StrictHostKeyChecking ask"/"StrictHostKeyChecking no"/g /etc/ssh/ssh_config
RUN mkdir /opt/config
COPY --from=build /tmp/myapp /opt/
COPY config/conf.yaml /opt/config/
WORKDIR /opt/
CMD ["./myapp"]