Compare the difference between dockerfile before and after docker-slim

procedure

  #Sample node.Create a Docker image for your js app
~ $ git clone https://github.com/docker-slim/examples.git

  # node_Move to the directory where ubuntu Dockerfile is located
~ $ cd examples/node_ubuntu/

  #Build Dockerfile and create an image
~ $ docker build -t my/sample-node-app .

  #For the created image, docker-Apply slim
~ $ docker-slim build my/sample-node-app

How much is the size reduction? ??

~ $ docker images
    REPOSITORY                TAG                 IMAGE ID            CREATED             SIZE
    my/sample-node-app.slim   latest              b2c7843a52fa        3 hours ago         14MB
    my/sample-node-app        latest              3c6ddc217be2        4 hours ago         414MB

The bottom is the original image, and the top is the optimized image. It seems that ".slim" is added to the image optimized by docker-slim. The size is reduced from 414MB to 14MB. What's happening? ..

Comparison of docker files

--Dockerfile of the image to which docker-slim is applied is in the following directory - [docker-slim directory]/.images/[YOUR_APP_IMAGE_ID]/artifacts/

Dockerfile-before


FROM ubuntu:14.04
RUN apt-get update && \
		apt-get install -y curl software-properties-common python-software-properties && \
		add-apt-repository ppa:chris-lea/node.js && \
		apt-get update && \
		apt-get install -y build-essential \
		nodejs && \
		mkdir -p /opt/my/service
COPY service /opt/my/service
WORKDIR /opt/my/service
RUN npm install
EXPOSE 1300
ENTRYPOINT ["node","/opt/my/service/server.js"]

Dockerfile-after


FROM scratch
LABEL docker-slim.version="darwin|Transformer|1.32.0|10b628fc3cd9f903237b9c31a6aba5ac4e6bc9c8|2020-08-24_06:14:32AM"
ENV PATH "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"

ADD files.tar /
WORKDIR /opt/my/service
EXPOSE 1300/tcp
ENTRYPOINT ["node","/opt/my/service/server.js"]

The FROM clause has changed from ubuntu: 14.04 to scratch. FROM scratch means that there is no base, and it seems to indicate that you are writing from the base OS part. It seems that the OS part is handled by files.tar, which is supposed to be a compressed version of the ADD ubuntu file system.

Reference link

--I tried using DockerSlim - https://scrapbox.io/kimihiro-n/DockerSlim_%E4%BD%BF%E3%81%A3%E3%81%A6%E3%81%BF%E3%81%9F

Recommended Posts

Compare the difference between dockerfile before and after docker-slim
Understand the difference between each_with_index and each.with_index
About the difference between irb and pry
[Java] Understand the difference between List and Set
[iOS] Understand the difference between frame and bounds
[Rails / ActiveRecord] About the difference between create and create!
Understand the difference between abstract classes and interfaces!
What is the difference between SimpleDateFormat and DateTimeFormatter? ??
Difference between vh and%
Difference between i ++ and ++ i
[Ruby] I thought about the difference between each_with_index and each.with_index
What is the difference between a class and a struct? ?? ??
[Rails] What is the difference between redirect and render?
[JAVA] What is the difference between interface and abstract? ?? ??
What is the difference between skip and pending? [RSpec]
[Rails] I investigated the difference between redirect_to and render.
What is the difference between Java EE and Jakarta EE?
[Swift] UITextField taught me the difference between nil and ""
Difference between product and variant
Difference between redirect_to and render
Rails: Difference between resources and resources
Difference between puts and print
Difference between redirect_to and render
Difference between CUI and GUI
Difference between mockito-core and mockito-all
Difference between class and instance
Difference between bundle and bundle install
Difference between ArrayList and LinkedList
Difference between render and redirect_to
Difference between List and ArrayList
Difference between .bashrc and .bash_profile
Difference between StringBuilder and StringBuffer
Difference between render and redirect_to
Difference between render and redirect_to
Difference between Java and JavaScript (how to find the average)
About the difference between "(double quotation)" and "single quotation" in Ruby
[Ruby] About the difference between 2 dots and 3 dots of range object.
What is the difference between an action and an instance method?
[Java] Check the difference between orElse and orElseGet with IntStream
Let's override the difference between == (identity) and equals method (equivalence)
The difference between programming with Ruby classes and programming without it
[Ruby] Difference between get and post
Difference between instance method and class method
Difference between render method and redirect_to
Find the difference between List types
Difference between interface and abstract class
[Java] Difference between Hashmap and HashTable
[Terminal] Difference between irb and pry
JavaServlet: Difference between executeQuery and executeUpdate
[Ruby] Difference between is_a? And instance_of?
Difference between == operator and eqals method
[Ruby] Difference between symbol variables and character string variables. About the difference between [: a] and ['a'].
Rough difference between RSpec and minitest
[Rails] Difference between find and find_by
Difference between instance variable and class variable
[JAVA] Difference between abstract and interface
Difference between Thymeleaf @RestController and @Controller
Difference between Stream map and flatMap
What is the difference between a web server and an application server?
[Java] Difference between array and ArrayList
Difference between primitive type and reference type