├── Healthcheck ├── docker-compose.yml └── healthcheck.sh └── Optimization └── GO └── helloworld-multistage ├── Dockerfile-alpine ├── Dockerfile-before ├── Dockerfile-multistage ├── README.md ├── docker-compose.yml ├── images ├── README.md ├── golang-18.png ├── golang-alpine.png └── golang-multistage.png └── main.go /Healthcheck/docker-compose.yml: -------------------------------------------------------------------------------- 1 | services: 2 | nginx: 3 | image: nginx:alpine 4 | container_name: nginx 5 | restart: always 6 | volumes: 7 | - ./healthcheck.sh:/bin/healthcheck.sh 8 | healthcheck: 9 | test: ['CMD', '/bin/healthcheck.sh'] 10 | interval: 10s 11 | timeout: 5s 12 | retries: 3 13 | ports: 14 | - '80:80' 15 | -------------------------------------------------------------------------------- /Healthcheck/healthcheck.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | URL=http://localhost/ 4 | 5 | RESPONSE=$(curl -s -o /dev/null -w '%{http_code}\n' "$URL") 6 | 7 | [ "$RESPONSE" = "200" ] && exit 0 || exit 1 -------------------------------------------------------------------------------- /Optimization/GO/helloworld-multistage/Dockerfile-alpine: -------------------------------------------------------------------------------- 1 | # this image size is 300 MG 2 | FROM golang:alpine 3 | 4 | WORKDIR /go/src/app 5 | RUN go mod init 6 | COPY main.go . 7 | RUN go build -o webserver . 8 | CMD ["./webserver"] 9 | -------------------------------------------------------------------------------- /Optimization/GO/helloworld-multistage/Dockerfile-before: -------------------------------------------------------------------------------- 1 | #This image size is 719MB 2 | FROM golang:1.8 3 | 4 | WORKDIR /go/src/app 5 | COPY main.go . 6 | RUN go build -o webserver . 7 | CMD ["./webserver"] 8 | 9 | -------------------------------------------------------------------------------- /Optimization/GO/helloworld-multistage/Dockerfile-multistage: -------------------------------------------------------------------------------- 1 | #This image size is 11.9 MG 2 | 3 | FROM golang:alpine as builder 4 | 5 | WORKDIR /go/src/app 6 | COPY main.go . 7 | RUN go mod init 8 | RUN go build -o webserver . 9 | 10 | FROM alpine 11 | WORKDIR /app 12 | COPY --from=builder /go/src/app/ /app 13 | CMD ["./webserver"] 14 | -------------------------------------------------------------------------------- /Optimization/GO/helloworld-multistage/README.md: -------------------------------------------------------------------------------- 1 | 2 | docker build -t hello:1 . 3 | 4 | docker images | grep hello 5 | 6 | docker run -itd -p 8010:8080 hello:3 7 | -------------------------------------------------------------------------------- /Optimization/GO/helloworld-multistage/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: "3" 2 | services: 3 | hellow: 4 | image: hello:3 5 | container_name: hello-go 6 | ports: 7 | - 80:8080 8 | -------------------------------------------------------------------------------- /Optimization/GO/helloworld-multistage/images/README.md: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /Optimization/GO/helloworld-multistage/images/golang-18.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/farshadnick/docker-tutorial/209bf71fc80b713a3407e344160c8f07dd2248f7/Optimization/GO/helloworld-multistage/images/golang-18.png -------------------------------------------------------------------------------- /Optimization/GO/helloworld-multistage/images/golang-alpine.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/farshadnick/docker-tutorial/209bf71fc80b713a3407e344160c8f07dd2248f7/Optimization/GO/helloworld-multistage/images/golang-alpine.png -------------------------------------------------------------------------------- /Optimization/GO/helloworld-multistage/images/golang-multistage.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/farshadnick/docker-tutorial/209bf71fc80b713a3407e344160c8f07dd2248f7/Optimization/GO/helloworld-multistage/images/golang-multistage.png -------------------------------------------------------------------------------- /Optimization/GO/helloworld-multistage/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | import( 3 | "fmt" 4 | "log" 5 | "net/http" 6 | ) 7 | func handler(w http.ResponseWriter, r *http.Request){ 8 | fmt.Fprintf(w,"Hello from the webserver") 9 | } 10 | func main(){ 11 | http.HandleFunc("/",handler) 12 | log.Fatal(http.ListenAndServe("0.0.0.0:8080", nil)) 13 | } 14 | --------------------------------------------------------------------------------