mirror of
https://github.com/yeasy/docker_practice.git
synced 2025-10-19 05:22:18 +00:00
Add multistage builds #226
This commit is contained in:
1
image/demo/multistage-builds/.gitignore
vendored
Normal file
1
image/demo/multistage-builds/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
app
|
12
image/demo/multistage-builds/Dockerfile
Normal file
12
image/demo/multistage-builds/Dockerfile
Normal file
@@ -0,0 +1,12 @@
|
||||
FROM golang:1.9-alpine
|
||||
RUN apk --no-cache add git
|
||||
WORKDIR /go/src/github.com/go/helloworld/
|
||||
RUN go get -d -v github.com/go-sql-driver/mysql
|
||||
COPY app.go .
|
||||
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o app .
|
||||
|
||||
FROM alpine:latest
|
||||
RUN apk --no-cache add ca-certificates
|
||||
WORKDIR /root/
|
||||
COPY --from=0 /go/src/github.com/go/helloworld/app .
|
||||
CMD ["./app"]
|
10
image/demo/multistage-builds/Dockerfile.build
Normal file
10
image/demo/multistage-builds/Dockerfile.build
Normal file
@@ -0,0 +1,10 @@
|
||||
FROM golang:1.9-alpine
|
||||
|
||||
RUN apk --no-cache add git
|
||||
|
||||
WORKDIR /go/src/github.com/go/helloworld
|
||||
|
||||
COPY app.go .
|
||||
|
||||
RUN go get -d -v github.com/go-sql-driver/mysql \
|
||||
&& CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o app .
|
9
image/demo/multistage-builds/Dockerfile.copy
Normal file
9
image/demo/multistage-builds/Dockerfile.copy
Normal file
@@ -0,0 +1,9 @@
|
||||
FROM alpine:latest
|
||||
|
||||
RUN apk --no-cache add ca-certificates
|
||||
|
||||
WORKDIR /root/
|
||||
|
||||
COPY app .
|
||||
|
||||
CMD ["./app"]
|
15
image/demo/multistage-builds/Dockerfile.one
Normal file
15
image/demo/multistage-builds/Dockerfile.one
Normal file
@@ -0,0 +1,15 @@
|
||||
FROM golang:1.9-alpine
|
||||
|
||||
RUN apk --no-cache add git ca-certificates
|
||||
|
||||
WORKDIR /go/src/github.com/go/helloworld/
|
||||
|
||||
COPY app.go .
|
||||
|
||||
RUN go get -d -v github.com/go-sql-driver/mysql \
|
||||
&& CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o app . \
|
||||
&& cp /go/src/github.com/go/helloworld/app /root
|
||||
|
||||
WORKDIR /root/
|
||||
|
||||
CMD ["./app"]
|
7
image/demo/multistage-builds/app.go
Normal file
7
image/demo/multistage-builds/app.go
Normal file
@@ -0,0 +1,7 @@
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
func main(){
|
||||
fmt.Printf("Hello World!");
|
||||
}
|
14
image/demo/multistage-builds/build.sh
Executable file
14
image/demo/multistage-builds/build.sh
Executable file
@@ -0,0 +1,14 @@
|
||||
#!/bin/sh
|
||||
|
||||
echo Building go/helloworld:build
|
||||
|
||||
docker build -t go/helloworld:build . -f Dockerfile.build
|
||||
|
||||
docker create --name extract go/helloworld:build
|
||||
docker cp extract:/go/src/github.com/go/helloworld/app ./app
|
||||
docker rm -f extract
|
||||
|
||||
echo Building go/helloworld:2
|
||||
|
||||
docker build --no-cache -t go/helloworld:2 . -f Dockerfile.copy
|
||||
rm ./app
|
Reference in New Issue
Block a user