Open liuzheng opened 4 years ago
Docker image build with multi-stage and save build time. Some code in Dockerfile is useless, such as
Dockerfile
Dockerfile: -ADD applog/ applog/ -ADD countries/ countries/ -ADD geodns-logs/ geodns-logs/ -ADD health/ health/ -ADD monitor/ monitor/ -ADD querylog/ querylog/ -ADD server/ server/ -ADD targeting/ targeting/ -ADD typeutil/ typeutil/ -ADD zones/ zones/ -ADD service/ service/ -ADD service-logs/ service-logs/ -ADD *.go build ./ +COPY . /goapp
There is no need to add code one by one. Use .dockerignore then one COPY .
.dockerignore
Dockerfile: +FROM golang as prepare +COPY go.mod go.sum /goapp/ +WORKDIR /goapp/ +RUN go mod download -ADD vendor/ vendor/ .dockerignore: +.git/ +.idea/ +vendor/ +dist/
This change because vendor/ not always same in any OS system. Use stage prepare to download packages can save time.
vendor/
prepare
make docker-build
Docker image build with multi-stage and save build time. Some code in
Dockerfile
is useless, such asThere is no need to add code one by one. Use
.dockerignore
then one COPY .This change because
vendor/
not always same in any OS system. Use stageprepare
to download packages can save time.Build Docker image