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

Docker learn the basics of 02-docker

2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

I. dcoker basic concept Mirror (image)

Mirroring, in essence, is equivalent to a file system. The image is read-only. In addition to providing programs, libraries, resources, configuration and other files needed for the container to run, it also packages some configuration parameters for the runtime, such as anonymous volumes, environment variables, users, and so on. The mirror does not contain any dynamic data, and its content will not be changed after it is built. An image can run multiple container, and the image can be created through dockerfile or downloaded from dicker hub/registory.

Container (container)

A container is essentially a process, but it runs in its own independent namespace, so the container can have its own root file system, its own network configuration, its own process space, and even its own user id space. To put it bluntly, it is running in an isolated environment.

Warehouse (repository)

A warehouse, as its name implies, is a space for storage. After the image is built, it can be easily run on the current host. However, if you want to use this image on other servers, we need a centralized service to store and distribute images, such as docker registry.

The image is equivalent to the packaged version. After the image is started, it runs in the container, and the repository is the place where the image is stored.

Hierarchical storage

Because the image contains the complete root file system of the operating system, its volume is often huge, so when designing docker, we make full use of Union FS technology and design it as a tiered storage architecture. Strictly speaking, an image is not a packaged file like an ISO, but a virtual concept, and its actual embodiment is not composed of a file, but a set of file systems, or a federation of file systems.

When the image is built, it will be built layer by layer, and the former layer serves as the foundation of the latter layer. After each layer is built, there will be no change, and the change on the latter layer will only occur on your own layer.

II. Docker's Cramp S model

Docker adopts Cramp S architecture, including client side and server side. The Docker daemon (Daemon) accepts requests from the client as a server and processes them (create, run, distribute containers)

Generally, the Docker daemon runs in the background of the host host, waiting to receive messages from the client. The Docker client provides a series of executable commands for users to interact with the Docker daemon capital:

Docker also provides us with Remote API to operate the daemon of Docker, which also means that we can control the running of Docker through our own process. The client and server can either run on the same machine or communicate through socket or RESTfuk API:

As for the communication between the client of Docker and the daemon, the connection method is socket connection, and there are three main connection methods:

Unix:///var/run/docker.socktcp://host:ipfd://socketfd

The nature of the complete Docker Cramp S connection can be generally expressed as follows:

iii. Use Docker Container Action # start a container docker run-it nginx / bin/bash# View Container docker ps [- a] [- l]-an all list all containers-l latest list recent containers # View specified container docker inspect name | id name refers to a specific container name Id is the unique identification of the container # start / stop container docker start | stop name | id# delete container docker rm name stopped | id# enters the running container # docker attach name | Ctrl+P Ctrl+Q docker exec-it name is used when id exits | exit# can be used to start the container running in the background docker-d. # View container log docker logs [- f] [- t] when id bash exits. [- tail] name | id-f-follows=true | false Default is false, display update-t-timestamps=true | false, default is false, display timestamp-tail= "all" | number of rows, log showing the latest number of lines # View the process in the container docker top name | id mirror operation # query image # docker search name [options]-automated=false, only show the automatically built image-no-trunc=false, not truncate the output-filter Add filter condition # pull image docker pull [OPTIONS] NAME [: TAG]-ALI all TAG tags false, download all mirrors (including all images) # push image docker push [OPTIONS] NAME [: TAG] # list image docker images [OPTIONS] [REPOSITORY]-apower allcolors false, display all images-f language filter = [], filter condition on display-no-trunc=false Specify that the data is not displayed in truncated form-QQuery id# false, but only the unique id# view image of the image docker inspect [OPTIONS] CONTAINER | IMAGE [CONTAINER | IMAGE]-fmaitype format = "" # build an image to build a docker image, which can save the changes to the container and use it again. Building images provides the ability to customize images, package and distribute services and their operating environments in the form of software. Docker provides two ways to build images:-build through containers: docker commit-- through Dockerfile: docker build 1. Use the commit command to build the image command: docker commit [OPTIONS] CONTAINER [REPOSITORY [: TAG]] parameter:-a hxl' authoring = "", specify the author information of the image-m hxl' message = "", and submit the message-whether to pause the container ccs-iMac:~ cc$ docker commit-a'- m 'image when committing. Building an image Docker using a Dockerfile file allows us to build a custom image in the form of a similar configuration file, in which you can specify the original image, the maintenance information of the custom image, the action taken on the original image, and the exposed port and other information. For example: Sample DockerfileFROM ubuntu:16.04MAINTAINER wgp "Kingdompin@163.com" RUN apt-get updateRUN apt-get install-y nginxEXPOSE 80 command: docker build [OPTIONS] DockerFile_PATH | URL |-Parameter:-force-rm=false-no-cache=false-pull=false-Q rm=true quiteware false, no information is output during construction-image-tscore = "", specify the output image name information # Image migration we make an image and generally share it with others. Docker provides several ways of migration, but there are two commonly used ones: 1. Use registory to share, optional Docker HUb and private repositories 2.docker load and docker save to package sharing warehouse operations

Warehouses are generally Dokcer Hub and private self-built registry. As for how to build private warehouses, this article will not describe them.

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