Giter Site home page Giter Site logo

theskyinflames / dockerlightningtalk Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 887 KB

A lightning talk about how to reduce Docker images

Makefile 10.79% Go 2.17% HTML 82.19% Dockerfile 4.85%
docker docker-images docker-images-downsize docker-image-size multi-stage multi-stage-docker multi-stage-build

dockerlightningtalk's Introduction

Minimizing Docker images lightning talk

A lightning talk about how to reduce Docker images. The goal is to explain how can we decrease the size of our Docker images and why it's important.

## Start the presentation:

This presentation uses the present tool from Go. You must install it and do:

  dockerLightningTalk git:(master) ✗ present
  2020/05/17 21:43:07 Open your web browser and visit http://127.0.0.1:3999

## Approach

I've taken a minimal service in golang as a example to be dockerized:

import (
	"fmt"
	"net/http"
)

func main() {
	http.HandleFunc("/", HelloServer)
	fmt.Println("server started on :8080")
	http.ListenAndServe(":8080", nil)
}

func HelloServer(w http.ResponseWriter, r *http.Request) {
	w.Write([]byte("Hello world!\n"))
}

From here, I dockerlize the above serivice in a four different ways. With each iteration, I get an smaller Docker image. All images does the same, dockerizing the above service. But all Dockerfiles are different:

  • First Dockerfile uses a Debian Linux as base image.
  • Second Dockerfile uses an Alpine Linux as base image.
  • Third Dockerfile uses multi stage building. This dereases dramatically the size of the docker image-
  • Fourth Dockerfile combines multi stage building and scratch image usage.

This is the result:

  docker images|grep hello-|sort -k1nr
  hello-1-debian        latest              a57e328870c3        27 minutes ago      818MB
  hello-2-alpine        latest              91b9333cc751        27 minutes ago      378MB
  hello-3-multi-stage   latest              151363ae52cd        27 minutes ago      13.1MB
  hello-4-ms-scratch    latest              d1ea8ed7079f        26 minutes ago      7.41MB

As you can see, we pass from a 818 Mb docker image to a 7.41 Mb one. The two images are equivalent and does the same, dockerizing the service.

## Check it out for yourself

  1. Compile the Dockerfiles
  make build-all
  1. List Docker images and compare its sizes
  make list-imgages

dockerlightningtalk's People

Contributors

theskyinflames avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.