Docker's image is too large. How can it become smaller?

Source: Internet
Author: User
Tags docker hub

Region ~ Region ~ Region ~ Docker is about to subvert the entire software industry. From the cloud computing platform to software development and testing, the entire SDLC will be highly dependent on docker.

There must be many discussions about docker in the circle. In short, docker only solves one problem:

 

QA: The program cannot be started !!!

Dev: No. It can be run on my machine.

 

You can learn more about the conversation. However, for those who have already invested in SSD, it is absolutely unacceptable to store 50 docker images of around Mb on the valuable SSD !! However, most of the images downloaded from docker hub are in this number, even greater than this. Looking at the disk space that is gradually eroded by docker, the landlord decided to make a huge reduction in docker files. The results show that the effect is remarkable. Please refer

Trembling, mortal! 100 MB of redis is compressed to only 7 MB !!!

 

First, correct the basic concepts:

1. docker is not a Virtual Machine (remember)

2. The complete operating system is not required for running the program in docker!

3. coreos, RHEL, Ubuntu, centos, etc. They are all operating systems!

 

The basic steps are as follows:

1. Use the install command of busybox to create a minimal system environment

2. to delete unnecessary system files, you need to analyze specific programs. The author has spent a lot of time analyzing each program, now, the landlord can almost roll back the dependencies of these apps.

3. Package these files into rootfs.tar

4. Use the Add command of dockerfile to generate an image using rootfs.tar

 

The landlord has no Code. The Code starts,

1. Generate a simplest rootfs.tar Based on redis 2.8.13

 1 FROM redis:2.8.13 2  3 # switch to root to build image 4 # ================================================= 5 USER root 6  7 # prepare rootfs 8 # ================================================= 9 RUN mkdir /rootfs10 WORKDIR /rootfs11 RUN mkdir bin etc dev dev/pts lib usr proc sys tmp12 RUN mkdir -p usr/lib64 usr/bin usr/local/bin13 RUN touch etc/resolv.conf14 RUN cp /etc/nsswitch.conf etc/nsswitch.conf15 RUN echo root:x:0:0:root:/:/bin/sh > etc/passwd16 RUN echo root:x:0: > etc/group17 RUN ln -s lib lib6418 RUN ln -s bin sbin19 20 # install busybox21 # =================================================22 ADD http://busybox.net/downloads/binaries/1.21.1/busybox-x86_64 /sbin/busybox23 RUN chmod +x /sbin/busybox24 RUN cp /sbin/busybox bin25 RUN busybox --install -s bin26 27 # extract redis-server28 # =================================================29 RUN cp /usr/local/bin/redis-server usr/bin/redis-server30 31 # extract redis-server‘s dependencies32 # =================================================33 RUN bash -c "cp /lib/x86_64-linux-gnu/lib{m,dl,pthread,c}.so.* lib64"34 RUN cp /lib64/ld-linux-x86-64.so.2 lib64/35 36 # build rootfs37 RUN tar cf /rootfs.tar .
Dockerfile

2. Use this rootfs.tar to generate the smallest redis Image File

1 FROM scratch2 MAINTAINER e2tox <[email protected]>3 ADD rootfs.tar /4 WORKDIR /data5 VOLUME /data6 # Define default command.7 EXPOSE 63798 ENTRYPOINT ["/usr/bin/redis-server"]9 CMD ["--port", "6379"]
Dockerfile

3. Run it and try again.

docker run --rm -it -p 6379:6379 microbox/redis

 

The image generated by this method is no different from the ordinary redis image. You can use it as much as you like. The landlord has released 30 GB of space first.

If you have more desire to explore, please visit the author's open source project http://microbox.io

Good night

 

Docker's image is too large. How can it become smaller?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.