makeporngreatagain.pro
yeahporn.top
hd xxx

Using multi-stage builds in Dockerfile

333
  1. Create some project directories:
    cd ~/
    mkdir efficient
    mkdir inefficient
    cd inefficient

     

  2. Create the source code file:
    vi helloworld.go
    package main
    import "fmt"
    func main() {
        fmt.Println("hello world")
    }

     

  3. Create the Dockerfile:
    vi Dockerfile
    FROM golang:1.12.4
    WORKDIR /helloworld
    COPY helloworld.go .
    RUN GOOS=linux go build -a -installsuffix cgo -o helloworld .
    CMD ["./helloworld"]

     

  4. Build and test the inefficient image:
    docker build -t inefficient .
    docker run inefficient
    docker image ls

     

  5. Switch to the efficient project directory and copy the files from the inefficient project:
    cd ~/efficient
    cp ../inefficient/helloworld.go ./
    cp ../inefficient/Dockerfile ./

     

  6. Change the Dockerfile to use a multi-stage build:
    vi Dockerfile
    FROM golang:1.12.4 AS compiler
    WORKDIR /helloworld
    COPY helloworld.go .
    RUN GOOS=linux go build -a -installsuffix cgo -o helloworld .
    
    FROM alpine:3.9.3
    WORKDIR /root
    COPY --from=compiler /helloworld/helloworld .
    CMD ["./helloworld"]

     

  7. Build and test the efficient image:
    docker build -t efficient .
    docker run efficient
    docker image ls
  8. Checkout the size of both images
Leave A Reply

Your email address will not be published.

baseofporn.com https://www.opoptube.com
Ads Blocker Image Powered by Code Help Pro

Ads Blocker Detected!!!

We have detected that you are using extensions to block ads. Please support us by disabling these ads blocker.