Docker Compose vs Multi-Stage Build

With this new version of Docker, a multi-stage build is being created, at least I have never heard of this before. And the question I have now is, should I use it as a standard Compose file?

I used docker-compose.yamlto run containers where a lot of images were involved, one for the web server and one for the database. With this new multi-stage build, can I use one single Dockerfilewith two commands FROMand what is it?

Will this multi-stage build permanently destroy Compose (since there are fewer images)?

+4
source share
2 answers

( docker stack deploy , ). - , . , . Compose , , , .. , .

, , , . docker-compose .

go. , . , . hello.go:

package main
import "fmt"
func main() {
        fmt.Printf("Hello, world.\n")
}

Docker:

ARG GOLANG_VER=1.8
FROM golang:${GOLANG_VER} as builder
WORKDIR /go/src/app
COPY . .
RUN go-wrapper download 
RUN go-wrapper install

FROM scratch
COPY --from=builder /go/bin/app /app
CMD ["/app"]

FROM, Dockerfile , . FROM go. FROM , . - . , . , docker build --target=builder ..

, :

$ docker build -t test-mult-stage .
Sending build context to Docker daemon  4.096kB
Step 1/9 : ARG GOLANG_VER=1.8
 ---> 
Step 2/9 : FROM golang:${GOLANG_VER} as builder
 ---> a0c61f0b0796
Step 3/9 : WORKDIR /go/src/app
 ---> Using cache
 ---> af5177aae437
Step 4/9 : COPY . .
 ---> Using cache
 ---> 976490d44468
Step 5/9 : RUN go-wrapper download
 ---> Using cache
 ---> e31ac3ce83c3
Step 6/9 : RUN go-wrapper install
 ---> Using cache
 ---> 2630f482fe78
Step 7/9 : FROM scratch
 ---> 
Step 8/9 : COPY --from=builder /go/bin/app /app
 ---> 96b9364cdcdc
Removing intermediate container ed558a4da820
Step 9/9 : CMD /app
 ---> Running in 55db8ed593ac
 ---> 5fd74a4d4235
Removing intermediate container 55db8ed593ac
Successfully built 5fd74a4d4235
Successfully tagged test-mult-stage:latest

$ docker images | grep 2630
<none>          <none>      2630f482fe78    5 weeks ago      700MB

$ docker images | grep test-mult-stage
test-mult-stage latest      5fd74a4d4235    33 seconds ago   1.56MB

, 1,5 , - 700 . , ​​ , , , , . , . .

+7

, . . gcc , gcc . , , bash, Docker. , , , .

+4

Source: https://habr.com/ru/post/1680445/


All Articles