Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use Docker to build Enterprise Custom Image

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

What the editor wants to share with you this time is how to use Docker to build enterprise-level custom images. The article is rich in content, and interested friends can learn about it. I hope you can get something after reading this article.

Preface

Before leaving work, the landlord received a request to build a custom image of his application according to the latest Docker image standard due to a change in the basic image standard. The current standard is as follows: the infrastructure group only provides three public images that all projects must access, which include: JDK8, Skywalking, and Arthas. If other images need to be added to the applications of their respective business groups, each business group will add a custom image on top of the public image provided by the infrastructure group. The structure figure is as follows:

Construction steps

Write Dockerfile

Based on the latest specification, we need to write a Dockerfile, then reference the basic image provided by the infrastructure group, and then add other images needed by the application. So the final Dockerfile file is as follows:

FROM basic image address RUN apk add needs to add a custom image.

Install the Docker environment under Centos7

Uninstall the old version

Older versions of Docker are called docker or docker-engine. If you have installed these programs, uninstall them and related dependencies.

$sudo yum remove docker\ docker-client\ docker-client-latest\ docker-common\ docker-latest\ docker-latest-logrotate\ docker-logrotate\ docker-engine

Install Docker Engine-Community

Use the Docker repository for installation

Before installing Docker Engine-Community on the new host for the first time, you need to set up the Docker repository. You can then install and update Docker from the repository.

Set up the warehouse

Install the required software packages. Yum-utils provides yum-config-manager, and the device mapper storage driver requires device-mapper-persistent-data and lvm2.

$sudo yum install-y yum-utils\ device-mapper-persistent-data\ lvm2

Use the following command to set up a stable warehouse.

$sudo yum-config-manager\-add-repo\ https://download.docker.com/linux/centos/docker-ce.repo

Install Docker Engine-Community

Install the latest version of Docker Engine-Community and containerd, or go to the next step to install a specific version:

$sudo yum install docker-ce docker-ce-cli containerd.io

If you are prompted to accept the GPG key, select Yes.

Are there multiple Docker warehouses?

If multiple Docker repositories are enabled, installations or updates that do not specify a version in the yum install or yum update command will always install the highest version, which may not suit your stability needs.

The Docker installation is not started by default. And the docker user group has been created, but there are no users under that user group.

To install a specific version of Docker Engine-Community, list the available versions in the repository, and then select and install:

1. List and sort the versions available in your repository. This example sorts the results by version number (from highest to lowest).

$yum list docker-ce--showduplicates | sort-rdocker-ce.x86_64 3virtual 18.09.0-3.el7 docker-ce-stabledocker-ce.x86_64 18.06.1.ce-3.el7 docker-ce-stabledocker-ce.x86_64 18.06.0.ce-3.el7 docker-ce-stable

2. Install a specific version through its full package name, which is the package name (docker-ce) plus the version string (the second column), from the first colon (:) to the first hyphen, separated by a hyphen (-). For example: docker-ce-18.09.1.

$sudo yum install docker-ce- docker-ce-cli- containerd.io

Start Docker.

$sudo systemctl start docker

Verify that Docker Engine-Community is installed correctly by running the hello-world image.

$sudo docker run hello-world

Start building an application custom image

Build a custom image based on Dockerfile file

Execute the following command in the directory where the Dockerfile file is located to build the custom image:

Sudo docker build-f Dockerfile-t your custom image name.

Log in before pushing to the enterprise private image harbor

Docker login enterprise private harbor address enter user name, enter password to complete login

Push the built custom image to the enterprise's private harbor

Sudo docker push your custom image name

Summary

Pass 1. Write Dockerfile 2. 0 for custom build images. Install Docker environment 3. Build a custom image 4. In the above four steps of uploading a custom image to harbor, we have completed the construction of the application custom image, and we can directly use the custom image in our own applications. The advantage of this is that based on the basic image, we can combine it at will to build an image that meets our application, which is more flexible, hierarchical and scalable.

After reading this article on how to use Docker to build enterprise-level custom images, if you think the article is well written, you can share it with more people.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report