How to make a centos base image

How to make a centos base image

Preface

Now the operating system used by my company is all centos7.4, and of course the application is also deployed on centos. If docker is used for deployment, it is natural to build your own application image based on the centos image; but you can also build a basic framework image between the centos basic image and the application image, such as: basic JDK image, image based on Python environment, etc.; I believe everyone has also encountered that after building an image, the Chinese printed out when deploying the application is garbled, the log time shows UTC time, which is 8 hours less than Beijing time, and when you want to see whether a certain process is up, you find that the telnet command, ps command, and netstat command are not available, and when you want to edit a file, you find that the vim command is also unavailable; today we will take a look at how to build an enhanced centos image based on the centos image;

Building a mirror repository

Before building your own image, you need a place to store your image so that you can use it directly later. There are two ways of thinking: The first is to build it on your own machine, and then upload it to your own cloud disk through the command docker save -o xxx.tar.gz xxx-image:v1.0 , and then download it to your local disk when you use it, and then docker load -i xxx.tar.gz ; this method is fine, but it is more cumbersome (packaging, uploading and downloading, and finding the directory when loading); the second is to create your own docker image registry, and for the locally built image, you only need to re-tag it, and docker push can complete it; when downloading, you only need to docker pull, and everything can be done on the command line, just thinking about it makes me feel a bit uncomfortable;

Having said so much, let's take a look at how to build your own image warehouse; (In this article, we only use Alibaba Cloud's warehouse and build our own namespace). Of course, you can also apply for a cloud host yourself, and then build a private server.

First log in to Alibaba Cloud, and then find the location of the container image service from the service, as shown in the following figure:

Click Container Mirror Service to enter the Mirror Warehouse creation interface as shown below

Click Create to enter the warehouse creation interface

After filling in the information, click Next to choose how to upload the image

Because my requirement is to build from a local warehouse, but I think local warehouse building is the most flexible way;

After creating the image storage location, you can create a Dockerfile locally to build your own image;

Build centos enhanced version image

1. First, create a Dockerfile file and put the following content into the file

FROM centos
MAINTAINER terry.king "[email protected]"

# Define the time zone parameter ENV TZ=Asia/Shanghai
RUN ls -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo '$TZ' > /etc/timezone
# Set the encoding RUN localedef -c -f UTF-8 -i zh_CN zh_CN.utf8
ENV LC_ALL "zh_CN.UTF-8"

# Install basic yum packages RUN yum install -y gcc gcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl-devel patch net-tools iproute telnet bind-utils wget kde-l10n-Chinese glibc-common

2. Log in to Alibaba Cloud Docker Registry

sudo docker login --username=your Alibaba Cloud account registry.cn-shenzhen.aliyuncs.com

The username used to log in is the full name of the Alibaba Cloud account, and the password is the password set when activating the service.

You can change your login password on the product console home page. It is the second button to create a mirror repository, set the registry login password to the left

3. Build the image and push it to the Registry

$ docker build -t terrylmay/centos .
$ docker tag terrylmay/centos registry.cn-shenzhen.aliyuncs.com/terrylmay/centos:[image version number]
$ docker push registry.cn-shenzhen.aliyuncs.com/terrylmay/centos:[image version number]

The default image version number is latest

Summarize

In this way, a series of problems mentioned in the preface can be solved when building an application image. It is convenient for you to quickly build your own application image;

You may also be interested in:
  • CentOS 6.5 makes a Docker image that can log in via ssh

<<:  Develop calculator example code using native javascript

>>:  Summary of MySQL5 green version installation under Windows (recommended)

Recommend

docker-maven-plugin packages the image and uploads it to a private warehouse

Table of contents 1. Introduction to docker-maven...

Summary of common docker commands

Docker installation 1. Requirements: Linux kernel...

MySQL8.0.18 configuration of multiple masters and one slave

Table of contents 1. Realistic Background 2. Agre...

Teach you how to install mysql database on Mac

Download MySQL for Mac: https://downloads.mysql.c...

Research on the effect of page sidebar realized by JS

Table of contents Discover: Application of displa...

Three ways to configure Nginx virtual hosts (based on domain names)

Nginx supports three ways to configure virtual ho...

Analysis and solution of abnormal problem of loading jar in tomcat

Description of the phenomenon: The project uses s...

Web Design Tutorial (6): Keep your passion for design

<br />Previous article: Web Design Tutorial ...

Detailed steps to install Nginx on Linux

1. Nginx installation steps 1.1 Official website ...

How to install nginx in centos7

Install the required environment 1. gcc installat...

Summary of Ubuntu backup methods (four types)

Method 1: To use respin, follow these steps: sudo...

How to smoothly upgrade and rollback Nginx version in 1 minute

Today, let's talk about a situation that is o...