PrefaceTaking the creation of a CentOS image as an example, this article describes the process of image customization, packaging, and pushing to a remote repository. The steps are relatively simple and you can get started quickly. Creation stepsCreate a CentOS base imageCreate a build directory and Dockerfile, and edit image-related settings in the Dockerfile. echo "Create directory docker/build/centos_7.8.2003 in the current user directory" > /dev/null mkdir -p ~/docker/build/centos_7.8.2003 echo "Create Dockerfile to ~/docker/build/centos_7.8.2003 directory" > /dev/null cat > ~/docker/build/centos_7.8.2003/Dockerfile << EOF # Specify the base image FROM centos:7.8.2003 # Set environment variable ENV LANG=zh_CN.UTF-8 \\ LANGUAGE=zh_CN:zh \\ LC_ALL=zh_CN.UTF-8 # Only execute these shell commands when building the image RUN yum update -y && \\ yum reinstall -y glibc-common && \\ yum install -y telnet net-tools && \\ yum clean all && \\ rm -rf /tmp/* rm -rf /var/cache/yum/* && \\ localedef -c -f UTF-8 -i zh_CN zh_CN.UTF-8 && \\ ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime EOF Refer to the Novice Tutorial - docker build to build an image. The format is # Parse ~/docker/build/centos_7.8.2003/Dockerfile to build a mirror named base-centos docker build -t base-centos ~/docker/build/centos_7.8.2003 After the build is complete, you can see the base image used and the new image generated by the build in the local image list. docker images Create a container and customize itUse the new image to create and enter a container. This container is a virtual CentOS system. echo "Create a container using the base-centos image and name it base-centos" > /dev/null docker run \ --name base-centos \ --privileged=true \ -dit \ base-centos \ /usr/sbin/init echo "Enter centos container" > /dev/null docker exec -it base-centos /bin/bash Customize the virtual system in the container, such as installing commonly used tools. In fact, these can also be written in the Dockerfile and defined after the RUN instruction. echo "vim: Edit file" > /dev/null yum install -y vim echo "lsof: convenient for viewing port information" > /dev/null yum install -y lsof echo "wget: file download" > /dev/null yum install -y wget echo "tree: View directory structure" > /dev/null yum install -y tree echo "install python" > /dev/null yum install -y python-devel echo "C compilation environment" > /dev/null yum install -y gcc gcc-c++ yum install -y zlib yum install -y zlib-devel yum install -y tcl build-essential tk gettext Create a new image with a custom container The command format is docker commit base-centos centos:7.8.2003_v1 At this point, the image is created and you can see the new image in the image list. Save and load the image tarball Save the image as a tarball in the format of docker save -o ~/docker/build/centos_7.8.2003/centos_7.8.2003.tar centos:7.8.2003_v1 Load the tarball to generate the image. docker load --input ~/docker/build/centos_7.8.2003/centos_7.8.2003.tar The load command is invalid if a duplicate image already exists. Push the image to the remote repository Docker logs in to the remote warehouse. The format is echo "Mark image address and version number" > /dev/null docker tag 66b1bc81e1f2 registry.cn-shanghai.aliyuncs.com/exposure/centos:7.8.2003_v1 echo "Push to remote repository" > /dev/null docker push registry.cn-shanghai.aliyuncs.com/exposure/centos:7.8.2003_v1 Reference LinksCSDN - Several Common CentOS7 Images for Docker Novice Tutorial - Docker Commands This is the end of this article about the complete process of Docker image creation. For more relevant content about Docker image creation, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: 24 Practical JavaScript Development Tips
>>: SASS Style Programming Guide for CSS
Import and export of Docker images This article i...
Result:Implementation Code html <link href=...
1. Environmental Preparation 1.MySQL installation...
Table of contents 1. Startup management of source...
The environment of this article is Windows 10, an...
Table of contents JavaScript Objects 1. Definitio...
Here we mainly use spring-boot out of the box, wh...
Table of contents Question: 1. First attempt 2. R...
The img tag in XHTML should be written like this:...
Here is how to install Tomcat-8.5.39 on centos7.6...
Solution: Add the following code in <head>: ...
This article shares the download, installation an...
Table of contents Overview Create a type definiti...
MySQL master-slave setup MySQL master-slave repli...
Table of contents 1. Initialize the array 2. Arra...