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

How to quickly install Nginx in Linux

Table of contents What is nginx 1. Download the r...

CSS3 achieves cool 3D rotation perspective effect

CSS3 achieves cool 3D rotation perspective 3D ani...

mysql calculation function details

Table of contents 2. Field concatenation 2. Give ...

Centos7 installation of MySQL8 tutorial

MySQL 8 new features: My personal opinion on MySQ...

React dva implementation code

Table of contents dva Using dva Implementing DVA ...

JS generates unique ID methods: UUID and NanoID

Table of contents 1. Why NanoID is replacing UUID...

Detailed explanation of how to adjust Linux command history

The bash history command in Linux system helps to...

Do you know how to use vue-cropper to crop pictures in vue?

Table of contents 1. Installation: 2. Use: 3. Bui...

Discuss the value of Web standards from four aspects with a mind map

I have roughly listed some values ​​to stimulate ...

Complete steps to set up automatic updates in CentOS 8

The best thing you can do for your data and compu...

How to let https website send referrer https and http jump referrer

This article describes a proposal for a metadata ...

JS 9 Promise Interview Questions

Table of contents 1. Multiple .catch 2. Multiple ...

mysql8.0.23 linux (centos7) installation complete and detailed tutorial

Table of contents What is a relational database? ...