alpine Makes Mirrors

Keywords: Docker JDK glibc Linux

alpine Make Mirror

Introduction to alpine Linux

1.Alpine Linux is a lightweight Linux distribution. It is different from the usual Linux distributions (centos, Ubuntu), Alpine uses musl libc and BusyBox to reduce system size and running resource consumption.
2.Alpine Linux provides its own package management tool: apk (note: apt-get in ubuntu), and we can query package information through https://pkgs.alpinelinux.org/packages
3. The Alpine Docker image inherits these advantages of the Alpine Linux distribution and is very small compared to other Linux Docker images

Compare common, uncompressed base images (see the current: latest tag):
Alpine - 4.8MB
centos - 124.8 MB
Debian - 125.1MB
Centos - 196MB

4. Alpine Linux version 3.10.0 is recommended, which is also the first version in the v3.10 stable series
alpine:3.10

Making JDK8 Mirror Based on alpine

Thin: Change centos7 system to alpine system
Replace jdk with a smaller jre
#1. Download Mirror

 docker pull alpine:latest


Upload glibc three files


#2. Create and edit dockerfile

  touch Dockerfile 
   vi Dockerfile 

   Note 1: dockerfile content
#1. Specify the base image and must be the first instruction 
FROM alpine:latest
#FROM alpine:3.10

#2. Indicate the author of the mirror and its e-mail 
MAINTAINER hsl "hsl@qq.com"

#3. When you build the image, specify the working directory for the image, and subsequent commands are based on this working directory. If it does not exist, the directory WORKDIR/hsl_docker/jdk will be created

#4. Copy some installation packages into the mirror, Syntax: ADD/COPY <src>... <dest>  
## Difference between ADD and COPY: ADD copies and decompresses, COPY copies only 
ADD jdk-8u221-linux-x64.tar.gz /hsl_docker/jdk/  
## glibc installation packages if downloading from the network is too slow, download and copy to the mirror ahead of time 
COPY glibc-2.29-r0.apk /hsl_docker/jdk/ 
COPY glibc-bin-2.29-r0.apk /hsl_docker/jdk/
 COPY glibc-i18n-2.29-r0.apk /hsl_docker/jdk/

#5. Update Alpine's software source is Aliyun, because pulling from the default source is too slow 
RUN echo http://mirrors.aliyun.com/alpine/v3.10/main/ > /etc/apk/repositories && \
    echo http://mirrors.aliyun.com/alpine/v3.10/community/ >> /etc/apk/repositories 
    RUN apk update && apk upgrade

#6. Run the specified command  
## Alpine linux does not install too many common software in order to simplify itself. The apk is similar to ubuntu's apt-get.  
## Used to install some common software Vs with the following syntax:apk add bash wget curl git make vim docker  
## WGet is a ftp/http transport tool under linux. Failure to install will result in an error'/bin/sh: wget: not found'. Install less WGet for online examples  
## ca-certificates Certificate Service, a pre-dependency for installing glibc 
RUN apk --no-cache add ca-certificates wget \
    && wget -q -O /etc/apk/keys/sgerrand.rsa.pub https://alpine-pkgs.sgerrand.com/sgerrand.rsa.pub \
    && apk add glibc-2.29-r0.apk glibc-bin-2.29-r0.apk glibc-i18n-2.29-r0.apk \
    && rm -rf /var/cache/apk/* glibc-2.29-r0.apk glibc-bin-2.29-r0.apk glibc-i18n-2.29-r0.apk

#7. Configuring environment variables 
ENV JAVA_HOME=/hsl_docker/jdk/jdk1.8.0_221 
ENV CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar 
ENV PATH=$JAVA_HOME/bin:$PATH

#Commands to execute when the container starts
#CMD ["java","-version"]

#3. Perform dockerfile to create a mirror

  docker build -t jdk8:v2.0 .


#4. Create and start containers

   docker create -it jdk8:v2.0    
   docker start container ID

#5. Enter the container

 docker exec -it container ID /bin/sh 
Note 1: Last sh instead of bash can also start up and enter the container directly
	 Docker run-it --name myjdk container ID

#6. Testing jdk

 java -version


Note 1:docker exec-it container ID/bin/sh logs in with the current account number (root) by default and can view the current user name through the whoami command.
You can also switch to another account number by following the command
Docker exec-it --user root <container ID>/bin/sh

Note 2: openjdk:8-jdk-alpine is the same image we created ourselves, but JDK is slimmer and smaller
 You can get down on your own and create a container to try it out

Note 3: The final finished mirror size is about 400M

Alpine Makes a jre Mirror

Minimum JRE base image of Docker container
#1. Download jre first at https://www.java.com/en/download/manual.jsp, about 77M
The final download is: /jre-8u221-linux-x64.tar.gz

#2.rz is uploaded to centos, deleted unused files, and recompressed


#Unzip

 tar -zxvf jre-8u221-linux-x64.tar.gz


#View jre size ()

   du -sh jre1.8.0_221

#Enter the jre directory and execute the slim command

cd jre1.8.0_221
#Execute the slimming command (see info, 111M after slimming)
#Delete text files
#Delete Text File
rm -rf COPYRIGHT LICENSE README release THIRDPARTYLICENSEREADME-JAVAFX.txtTHIRDPARTYLICENSEREADME.txt Welcome.html \
#Delete other useless files
rm -rf lib/plugin.jar \
	lib/ext/jfxrt.jar \
	bin/javaws \
	lib/javaws.jar \
	lib/desktop \
	plugin \
	lib/deploy* \
	lib/*javafx* \
	lib/*jfx* \
	lib/amd64/libdecora_sse.so \
	lib/amd64/libprism_*.so \
	lib/amd64/libfxplugins.so \
	lib/amd64/libglass.so \
	lib/amd64/libgstreamer-lite.so \
	lib/amd64/libjavafx*.so \
	lib/amd64/libjfx*.so


#Return to the parent directory and repackage the jre

   cd ../
      tar -zcvf jre1.8.0_221.tar.gz jre1.8.0_221




#3. Create and edit dockerfile
Note 1:dockerfile is as follows

#1. Specify the base image and must be the first instruction 
FROM alpine:latest
#FROM alpine:3.10

#2. Indicate the author of the mirror and its e-mail 
MAINTAINER hsl"hsl@qq.com"

#3. When you build the image, specify the working directory for the image, and subsequent commands are based on this working directory. If it does not exist, the directory will be created
 WORKDIR /hsl_docker/jdk

#4. Copy some installation packages into the mirror, Syntax: ADD/COPY <src>... <dest>
## Difference between ADD and COPY: ADD copies and decompresses, COPY copies only
## Note ~~Uploaded slim jre 
ADD jre1.8.0_221.tar.gz /hsl_docker/jdk/
## glibc installation packages if downloading from the network is too slow, download and copy to the mirror ahead of time 
COPY glibc-2.29-r0.apk /hsl_docker/jdk/ 
COPY glibc-bin-2.29-r0.apk /hsl_docker/jdk/ 
COPY glibc-i18n-2.29-r0.apk /hsl_docker/jdk/

#5. Update Alpine's software source is Aliyun, because pulling from the default source is too slow 
RUN echo http://mirrors.aliyun.com/alpine/v3.10/main/ > /etc/apk/repositories && \
    echo http://mirrors.aliyun.com/alpine/v3.10/community/ >> /etc/apk/repositories 
    RUN apk update && apk upgrade

#6. Run the specified command
## Alpine linux does not install too many common software in order to simplify itself. The apk is similar to ubuntu's apt-get.
## Used to install some common software Vs with the following syntax:apk add bash wget curl git make vim docker
## WGet is a ftp/http transport tool under linux. Failure to install will result in an error'/bin/sh: wget: not found'. Install less WGet for online examples
## ca-certificates Certificate Service, a pre-dependency for installing glibc 
RUN apk --no-cache add ca-certificates wget \
    && wget -q -O /etc/apk/keys/sgerrand.rsa.pub https://alpine-pkgs.sgerrand.com/sgerrand.rsa.pub \ 
    && apk add glibc-2.29-r0.apk glibc-bin-2.29-r0.apk glibc-i18n-2.29-r0.apk \ 
    && rm -rf /var/cache/apk/* glibc-2.29-r0.apk glibc-bin-2.29-r0.apk glibc-i18n-2.29-r0.apk

#7. Configuring environment variables
## Notice ~~No jdk, just point to jre 
ENV   JAVA_HOME=/hsl_docker/jdk/jre1.8.0_221 
ENV 	CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar 
ENV PATH=$JAVA_HOME/bin:$PATH

#Commands to execute when the container starts
#CMD ["java","-version"]

#4. Execute dockerfile to create a mirror

 docker build -t jdk8:v3.0 .



#5. Create and start containers

 docker create -it jdk8:v3.0    
  docker start container ID

#6. Enter the container

docker exec -it container ID /bin/sh 


#7. Testing jdk

 java -version
   Note 1: openjdk:8-jdk-alpine is the same image we created ourselves, but JDK is slimmer and smaller.
        In addition, there are some differences between openjdk and jdk, you can see the data "14 OpenJDK and JDK Difference Analysis - Short Book. mht" to understand

   Note 2: Alpine has a time zone problem when making JDK8 images. You can use the time zone view command to see

The results of the three versions of jdk mirror are as follows:

Made of V1.0:centos7+jdk1.8
V2.0: Made of alpine3.10+jdk1.8
V3.0: Made from alpine3.10+jre1.8+Slim command

Docker image uploaded to Aliyun

Upload the Docker image to Aliyun (or download the image from Ayun)

preparation in advance

#1. Register Aliyun Account
Aliyun official website link: https://dev.aliyun.com
#2. Login Account
#3. Configure Docker Accelerator
Note: Search for Container Mirror Service
#4. Namespace for creating a mirror repository
For example:hsl
#5. Create a mirror warehouse (create a mirror warehouse with a code hosting site bound, for example: github)
For example: image-test

##push mirror
Push Mirror to Registry
#1. Log in to the doker warehouse in Ali Cloud. - username is the user name of Ali Cloud. In addition, the password is the password set when opening the mirror service.

Forget your password by clicking on the menu Container Mirror Service -> Default Instance -> Access Credentials to modify it

 docker login --username=hsl registry.cn-shenzhen.aliyuncs.com

#2. Add tag s for local mirrors

  docker tag [ImageId] registry.cn-shenzhen.aliyuncs.com/hsl/alpine_jre:[Mirror Version Number]

#3. Push Mirror (jdk8-alpine:1.0)

docker push registry.cn-shenzhen.aliyuncs.com/hsl/alpine_jre:[mirror version number]

Example:
docker tag 238f4a774e9b registry.cn-shenzhen.aliyuncs.com/hsl/alpine_jre:v1.0
docker push registry.cn-shenzhen.aliyuncs.com/hsl/alpine_jre:v1.0

Pull mirror

#1. Log in to the doker warehouse in Aliyun

 docker login --username=hsl registry.cn-shenzhen.aliyuncs.com

#Pull mirror from Registry

docker pull registry.cn-shenzhen.aliyuncs.com/hsl/alpine_jre:[mirror version number]

Note 1: Repository is a centralized storage area for mirrors, divided into public and private warehouses
Sometimes it is easy to confuse a warehouse with a registered server. In fact, a registered server is a specific server that stores a warehouse. There can be multiple warehouses on each registered server and multiple mirrors underneath each warehouse.

110 original articles published. 1. Visits 4349
Private letter follow

Posted by kanetan on Tue, 25 Feb 2020 17:23:37 -0800