GithubHelp home page GithubHelp logo

danillouz / docker-multi-stage-build-experiment Goto Github PK

View Code? Open in Web Editor NEW
0.0 3.0 0.0 5.82 MB

Experimenting with Docker Multi Stage Builds to see image size impact

License: MIT License

JavaScript 100.00%
docker docker-image docker-image-size docker-multi-stage-build

docker-multi-stage-build-experiment's Introduction

Docker Multi Stage Builds

Experimenting with Docker Multi Stage Builds to see image size impact.

Tests

I ran a couple of tests modifying the .dockerignore and Dockerfile using a simple Node ExpressJS app.

App Structure

First I ran npm init -y, then npm i express and npm i -D eslint prettier. After installing all dependencies I created a src dir with a single file called app.js with the following contents:

'uses strict';

const express = require('express');

const app = express();

app.use('/', function(req, res, next) {
  res.json({
    status: 'ok'
  });
});

app.listen(8888);

As well as a .dockerignore, Dockerfile and basic README.md. This gives the following structure:

node_modules
src/
  app.js
.dockerignore
Dockerfile
package-lock.json
package.json
README.md

Test 1 - EMPTY Dockerignore, NO Multi Stage Build

First I wanted to see how the Docker Build Context is affected. Therefore I build an image with an empty .dockerignore using node:9.6 as a base image, without multi stage build.

Navigate to /test-1 and run:

docker build -t msb-node-1 .
DOCKER ARTIFACT SIZE
Build Context 23.48 MB
Image 680 MB

Test 2 - Dockerignore, NO Multi Stage Build

Now we only send the package files and source code using node:9.6 as a base image, without multi stage build.

Navigate to /test-2 and run:

docker build -t msb-node-2 .
DOCKER ARTIFACT SIZE
Build Context 57.86 kB
Image 680 MB

Test 3 - Dockerignore, Multi Stage Build

Now we only send the package files and source code using node:9.6 as base images, with multi stage build.

Navigate to /test-3 and run:

docker build -t msb-node-3 .
DOCKER ARTIFACT SIZE
Build Context 57.86 kB
Image 678 MB

Test 4 - Dockerignore, Multi Stage Build, Alpine Base Images

Now we only send the package files and source code using node:9.6-alpine as base images, with multi stage build.

Navigate to /test-4 and run:

docker build -t msb-node-4 .
DOCKER ARTIFACT SIZE
Build Context 57.86 kB
Image 69.7 MB

๐Ÿ˜Ž

The build context size is printed when running the docker build command, for example:

build-context

And the image size is printed when running docker images, for example:

images

Resources

docker-multi-stage-build-experiment's People

Watchers

 avatar  avatar  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.