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 analyze the introduction principle and basic Application of Dcoker

2025-01-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)05/31 Report--

This article will explain in detail how to analyze the basic principles and basic application of Dcoker. The content of the article is of high quality, so the editor will share it with you for reference. I hope you will have a certain understanding of the relevant knowledge after reading this article.

To understand Docker, it is enough to understand the following figure, where there are five objects: image, container, image repository, backup file, Dockerfile, and there are multiple commands marked in blue font to convert and generate various objects, which are described below:

Mirror image

You can simply understand that an image is a compressed package in which there is your program or code, as well as a file system, the so-called file system, which packages all the necessary files, executable programs, runtime, etc., of a standard operating system.

The reason why Docker solves the problem of consistency of the program execution environment is to package the application and the file system together. When the program runs, it loads dependencies from your packaged image file system. For example, if your program relies on JDK1.8, package the basic library of JDK1.8 in the image, and then no matter what environment the image is deployed to, no matter which host has JDK installed or not. Or with any version of JDK installed, your application will be able to load the JDK1.8 in the image consistently when it starts, avoiding deployment problems and runtime BUG caused by inconsistent environments.

The image can be identified by ID or name, where ID is a hash value in SHA256 format, for example:

B1183dab1c4049b9b9d0d0dff17d2eb04e8d9caf873f7ff505ff9fe8909e2a48

It can be abbreviated as b1183dab1c40

The image name is composed of the image name and Tag, with a colon in the middle. If Tag is omitted, it represents latest, for example:

# official Docker image, omitting the official Tagubuntu# Docker image. Specify the image in the non-Docker official maichong/ubuntu:16.04# pulse cloud repository on Tagubuntu:16.04# Docker Hub, with the image repository address maichong.io/project/ubuntu:16.04.

You can use the docker tag command to put a new label on an existing image, such as:

# add a new tag maichong.io/project/ubuntu:16.04docker tag ubuntu:16.04 maichong.io/project/ubuntu:16.04 to ubuntu:16.04

View a list of all the images on the current system:

> docker imagesREPOSITORY TAG IMAGE ID CREATED SIZEubuntu 16.04 e13f3d529b1a 6 days ago 115MB container

It is easy to understand that the image is "dead" and is a "static" file stored on disk, while the container is a running, in-memory, "dynamic" instance. Of course, the container is not necessarily running, the container can also be stopped.

With the docker run command, you can launch a container from an image, and an image can launch unlimited copies of containers. Each container is isolated from each other, and each container can be understood as a virtual machine. Each container has its own IP, file system, and so on.

Compared with the virtual machine, although the network, files and other resources of the container are isolated, the kernel of the shared host, that is, Docker does not start the kernel for each container from scratch, but runs the programs in the container in the kernel of the current host system, which has a great performance advantage over the VM virtual machine, so Docker is called lightweight virtualization.

You can control the start, stop and restart of the container through docker start / docker stop / docker restart.

Running the docker commit command generates a new version of the image of the running container, but it is recommended that you use Dockerfile to generate the image.

Dockerfile

In short, a Dockerfile is a configuration file that generates an image, for example:

# specify tomcat version FROM tomcat:8.5.32-jre8# specified working directory WORKDIR / app# copy the packaged server.jar to the image # you can use the build service of Pulse Cloud to package the source code online into the jarADD server.jar / app/server.jar# setup image startup command CMD java-jar / app/server.jar# declare the port EXPOSE 8080 to listen on

The file first declares the basic image of the image. In general, the image you build depends on a basic image, just like if you install software on a computer if the computer already has an operating system.

Then Dockerfile records the steps of generating a new image, including copying files, executing commands, and so on.

Dockerfile also contains declarations of other information, such as environment variables, marking ports that need to be open, and so on.

Using the docker build command, you can follow the steps recorded in Dockerfile to generate a new image step by step.

Executing commands in a running container, installing software, and then running docker commit can also generate a new image, but don't do this. Because, using Dockerfile, you can record the generation process of the image, and you can adjust the steps at any time to regenerate the image. This is the legendary infrastructure or code, which treats the configuration of the underlying environment as software programming.

Backup file

You can use the docker save command to export the image generated on your computer to a tar package file, and then use it to back up the data, or copy the file to another computer, import the image with the docker load command, and realize the image distribution.

However, this is very troublesome, especially for remote transmission. Please use the image repository for unified management and distribution.

Image warehouse

Image repository is a service that provides image storage online. Use docker pull to pull (download) the image from the image repository, and use the docker push command to push (upload) the local image to the image repository.

Usually, all the images we use are from the Docker official repository http://hub.docker.com. For enterprise users, Pulse Cloud also provides an enterprise private image repository. You must have the permission to specify a project and log in through docker login maichong.io before you can push and pull images into the pulse cloud.

On how to analyze the basic principles of Dcoker and the basic application of sharing here, I hope that the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

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