How to make Docker images smaller in Linux systems

  
                

Mirroring is often very large in Linux, but using Docker images is an exception. With images made with Linux Docker, the small may be only a few M. This article will introduce how to make Docker images smaller in Linux systems.

conventional image writing:

FROM ubuntu: 12.04

RUN apt-get update

RUN apt-get install -y nginx zip Curl

RUN echo “daemon off;” 》 /etc/nginx/nginx.conf

RUN curl -o /usr/share/nginx/www/master.zip -L Https://codeload.github.com/gabrielecirulli/2048/zip/master

RUN cd /usr/share/nginx/www/&& unzip master.zip && mv 2048-master /*. && rm -rf 2048-master master.zip

EXPOSE 80

CMD [“/usr/sbin/nginx”, “-c”, “/etc/Nginx/nginx.conf”]

Linux makes Docker images smaller

Based on ubuntu12.04, first update, then install nginx, zip, curl, configure nginx, download 2048 Code, decompress and put it in the specified location, delete the original file, throw port 80, and finally execute the command.

Such a dockerfile is no longer familiar, just like the docker hub or other teaching documentation. Next, let's talk about the middle of the problem.

1. How long does it take to pull a ubuntu, and how much space does it take? (Beginners have a lot of headaches at this step.) 2. What is the pain of updating Ubuntu without adding a Chinese image source? 3, configuration 4, the entire generated mirror is huge, playing a 2048 does not need to be so complicated.

Ask questions, don't give a solution to be a rogue, or look at the dockerfile:

FROM alpine:latest

MAINTAINER alex [email protected]

RUN apk --update add nginx

COPY . /usr/share/nginx/html

EXPOSE 80

CMD [“nginx”, “-g”, “daemon off;”]

Simplified use of dockerfile and base mirror and github features, can be less than one less sentence, move hands, so build, the entire image is no more than 10M, look back at the previous image, how much a ubuntu, ah, It is really necessary for home.

The above is how to make the Docker image smaller in the Linux system. The smaller the Linux image, the less space it takes, and the installation is faster.

Copyright © Windows knowledge All Rights Reserved