Docker custom image upload to Alibaba Cloud

Alpine makes jdk mirror

Introduction to alpine Linux
1. Alpine Linux is a light Linux distribution, which is different from the usual Linux distributions. Alpine uses musl libc and
BusyBox to reduce the size of the system and the resource consumption during runtime.
2. Alpine Linux provides its own package management tool: apk (note: apt-get in ubuntu), we can query package information through https://pkgs.alpinelinux.org/packages
3. Alpine Docker image inherits Alpine Linux These advantages of the distribution, compared to other Linux Docker images, its size is very small.
Compare the commonly used, uncompressed basic images (check the current: latest tab):
Alpine-4.8MB
centos-124.8 MB
Debian-125.1MB
Centos-196MB
4. It is recommended to use Alpine Linux version 3.10.0, which is also the first version of the v3.10 stable series
alpine: 3.10

Making JDK8 mirror based on alpine
#1. Download the mirror
docker pull alpine:latest

#2. Create and edit dockerfile
touch Dockerfile
vi Dockerfile
Note 1: Dockerfile content

#1.指定基础镜像,并且必须是第一条指令
FROM alpine:latest
#FROM alpine:3.10

#2.指明该镜像的作者和其电子邮件
MAINTAINER xyz "[email protected]"

#3.在构建镜像时,指定镜像的工作目录,之后的命令都是基于此工作目录,如果不存在,则会创建目录
WORKDIR /xieminglu_docker/jdk

#4.将一些安装包复制到镜像中,语法:ADD/COPY <src>... <dest>
## ADD与COPY的区别:ADD复制并解压,COPY仅复制
ADD jdk-8u221-linux-x64.tar.gz /xieminglu_docker/jdk/
## glibc安装包如果从网络下载速度实在是太慢了,先提前下载复制到镜像中
COPY glibc-2.29-r0.apk /xieminglu_docker/jdk/
COPY glibc-bin-2.29-r0.apk /xieminglu_docker/jdk/
COPY glibc-i18n-2.29-r0.apk /xieminglu_docker/jdk/

#5.更新Alpine的软件源为阿里云,因为从默认官源拉取实在太慢了
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.运行指定的命令
## Alpine linux为了精简本身并没有安装太多的常用软件,apk类似于ubuntu的apt-get,
## 用来安装一些常用软V件,其语法如下:apk add bash wget curl git make vim docker
## wget是linux下的ftp/http传输工具,没安装会报错“/bin/sh:   wget: not found”,网上例子少安装wget
## ca-certificates证书服务,是安装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.配置环境变量
ENV JAVA_HOME=/xieminglu_docker/jdk/jdk1.8.0_221
ENV CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
ENV PATH=$JAVA_HOME/bin:$PATH

#容器启动时需要执行的命令
#CMD ["java","-version"]

Insert picture description here
#3. Execute dockerfile to create a mirror
docker build -t jdk8:v2.0.

#4. Create and start the container
docker create -it jdk8:v2.0
docker start container ID

#5. Enter the container
docker exec -it container ID /bin/sh

Note 1: Finally, sh instead of bash
can also be started directly and enter the container
docker run -it --name myjdk container ID

#6. Test jdk
java -version

Note 1: docker exec -it container ID /bin/sh uses the current account (ie root) to log in by default. You can view the current user name through the whoami command, and
you can also switch to other accounts through the following command
docker exec -it --user root < Container ID> /bin/sh

Note 2: The image of openjdk:8-jdk-alpine is the same as the image we created by ourselves, except that the JDK has been thinner and smaller in size
. You can download it yourself and create a container to try

Note 3: The mirror size after the final production is about 400M

Alpine makes jre mirror

The smallest JRE basic image of Docker container
#1. First download jre, the
download address is https://www.java.com/en/download/manual.jsp, probably the
final downloaded data of 77M is: /jre-8u221-linux -x64.tar.gz

#2.rz upload to centos, delete useless files, and recompress

  #解压
  tar -zxvf jre-8u221-linux-x64.tar.gz
  #查看jre大小(瘦身前230M)
  du -sh jre1.8.0_221
  #进入jre目录,并执行瘦身命令
  cd jre1.8.0_221
  #执行瘦身命令(命令见资料,瘦身后111M)
#删除文本文件
rm -rf COPYRIGHT LICENSE README release THIRDPARTYLICENSEREADME-JAVAFX.txtTHIRDPARTYLICENSEREADME.txt Welcome.html \
#删除其他无用文件
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, repack jre
cd …/
tar -zcvf jre1.8.0_221.tar.gz jre1.8.0_221

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

#1.指定基础镜像,并且必须是第一条指令
FROM alpine:latest
#FROM alpine:3.10

#2.指明该镜像的作者和其电子邮件
MAINTAINER xyz "[email protected]"

#3.在构建镜像时,指定镜像的工作目录,之后的命令都是基于此工作目录,如果不存在,则会创建目录
WORKDIR /xieminglu_docker/jdk

#4.将一些安装包复制到镜像中,语法:ADD/COPY <src>... <dest>
## ADD与COPY的区别:ADD复制并解压,COPY仅复制
## 注意~~~上传的瘦身后的jre
ADD jre1.8.0_221.tar.gz /xieminglu_docker/jdk/
## glibc安装包如果从网络下载速度实在是太慢了,先提前下载复制到镜像中
COPY glibc-2.29-r0.apk /xieminglu_docker/jdk/
COPY glibc-bin-2.29-r0.apk /xieminglu_docker/jdk/
COPY glibc-i18n-2.29-r0.apk /xieminglu_docker/jdk/

#5.更新Alpine的软件源为阿里云,因为从默认官源拉取实在太慢了
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.运行指定的命令
## Alpine linux为了精简本身并没有安装太多的常用软件,apk类似于ubuntu的apt-get,
## 用来安装一些常用软V件,其语法如下:apk add bash wget curl git make vim docker
## wget是linux下的ftp/http传输工具,没安装会报错“/bin/sh:   wget: not found”,网上例子少安装wget
## ca-certificates证书服务,是安装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.配置环境变量
## 注意~~~没有jdk啦,直接指向jre
ENV JAVA_HOME=/xieminglu_docker/jdk/jre1.8.0_221
ENV CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
ENV PATH=$JAVA_HOME/bin:$PATH

#容器启动时需要执行的命令
#CMD ["java","-version"]

#4. Execute dockerfile to create a mirror
docker build -t jdk8:v3.0.

#5. Create and start the container
docker create -it jdk8:v3.0
docker start container ID

#6. Enter the container
docker exec -it container ID /bin/sh

#7. Test jdk
java -version

Note 1: The image of openjdk:8-jdk-alpine is the same as the image created by ourselves, except that the JDK has been thinner and smaller.
In addition, there is a certain difference between openjdk and jdk, you can read the information "14 The difference between OpenJDK and JDK-简书.mht" to understand

Note 2: Alpine makes JDK8 mirroring because of the time zone problem. You can use the time zone view command to take a look

The results of the three versions of jdk mirroring are as follows:
V1.0: made by centos7+jdk1.8 and made by
V2.0: made by alpine3.10+jdk1.8 and made by
V3.0: made by alpine3.10+jre1.8+ thinning command Become
Insert picture description here

Upload Docker image to Alibaba Cloud

Upload the Docker image to Alibaba Cloud (or download the image from Ayun )
Preliminary preparation
#1. Register an
Alibaba Cloud account Alibaba Cloud official website link: https://dev.aliyun.com
#2. Login account
#3. Configure Docker accelerator
Note: Search for "container mirroring service"
#4. Create the namespace of the mirror warehouse
For example: xieminglu
#5. Create a mirror warehouse (when creating a mirror warehouse, bind a code hosting website, such as github)
For example: image-test

push(推)Mirror
#1. Log in to Alibaba Cloud's doker warehouse, –username is the username of Alibaba Cloud, and the password is the password set when the mirroring service is activated. #If
you forget the password, click the menu: "Container Mirroring Service"- >"Default instance" -> "Access Credentials" to modify
docker login --username=xieminglu registry.cn-hangzhou.aliyuncs.com
#2. Add a tag to the local image
docker tag [ImageId] registry.cn-hangzhou.aliyuncs. com/xieminglu/alpine_jre:[Mirror version number]
#3. Push mirror (jdk8-alpine:1.0)
docker push registry.cn-hangzhou.aliyuncs.com/xieminglu/alpine_jre:[Mirror version number]
Example:
docker tag 238f4a774e9b registry .cn-hangzhou.aliyuncs.com/xieminglu/alpine_jre:v1.0
docker push registry.cn-hangzhou.aliyuncs.com/xieminglu/alpine_jre:v1.0

#pull(拉)镜
# 1. Log in to Alibaba Cloud's doker warehouse
docker login --username=xieminglu registry.cn-hangzhou.aliyuncs.com #Pull the
image from the Registry
docker pull registry.cn-hangzhou.aliyuncs.com /xieminglu/alpine_jre:[Mirror version number]

Note 1: Repository is a place where images are stored centrally. It is divided into public and private warehouses.
Sometimes it is easy to confuse the warehouse with the registration server (register). In fact, the registration server is the specific server that stores the warehouse. There are multiple warehouses, and there can be multiple mirrors under each warehouse

Insert picture description here
Insert picture description here
Insert picture description here

Guess you like

Origin blog.csdn.net/xieminglu/article/details/103597017