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

Best getting started at Docker- Enterprise level

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

Share

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

1. Background

* Docker is an open source Container container engine based on LXC technology from Docker.inc. The source code is hosted on GitHub, based on the Go language and open source in accordance with the Apache2.0 protocol.

The goal of the Docker project is to implement a lightweight operating system virtualization solution.

* Docker provides resource isolation and security of containers through kernel virtualization technologies (namespaces, cgroups, etc.). Because Docker is isolated through the virtualization of the operating system layer, the Docker container does not need additional operating system overhead like virtual machine VM to improve resource utilization.

two。 advantage

* simple deployment

* easy to manage

* start the application in seconds

* use the same kernel as the host to reduce performance loss

* High isolation

* Image is built once and runs everywhere

3. Application scenario

* simplified configuration, unified configuration, quick start through image (Simplifying)

* Code pipeline management, development environment-> test environment-> pre-production environment-> grayscale release-> official release. Docker implements rapid migration (Code Oioeline Management) here.

* Development efficiency. For developers, if you have an image, you can start the container directly (Developer Productivity)

* Application isolation. Compared with the complete isolation of virtual machines, docker will save resources (Applsolation).

* Server consolidation, one server running multiple docker containers to improve server utilization (Server Consolidation)

* debugging capability, debug debugging (Debugging Capabilties)

* Multi-tenancy, one tenant with multiple users, similar to Alibaba Public Cloud with multiple users under one project (Multi-tenancy)

* Rapid deployment, no need to start the operating system, and achieve second-to-second deployment (Rapid Deplovment)

4. Attention related to docker

* Container is different from virtual machine

* Container theory recommends a single process

* containers are not as mature as virtual machines

* the container can be started in a fraction of a second

* containers have proved their value in large-scale environments

* IT staff call containers lightweight

* Docker has become synonymous with container, but it is not the only provider

* Container can save IT manpower and speed up business update efficiency

5. Docker and the meaning of the container itself

* Product oriented: simplify the delivery process

* for development: simplify the configuration of the environment

* Test-oriented: multi-version testing

* for operation and maintenance: simplify environmental problems

* Architecture-oriented: automatic expansion [micro-service]

6. Reasons for using Docker

As a new way of virtualization, Docker has many advantages over the traditional way of virtualization.

First of all, the startup of the Docker container can be achieved in seconds, which is much faster than the traditional virtual machine approach. Second, Docker has low utilization of system resources, and thousands of Docker containers can be run on a single host at the same time.

6. Related concepts of docker

* * Image [p_w_picpath]

* Docker image is a read-only template.

For example, an image can contain a complete CentOS operating system environment with only Apache or other applications that the user needs.

Images can be used to create Docker containers.

Docker provides a simple mechanism to create or update an existing image, and users can even download an image from someone else to use it directly.

* * Container [container]

* Docker uses containers to run applications.

A container is a running instance created from an image. It can be started, started, stopped, and deleted. Each container is isolated from each other and ensures a secure platform.

Think of the container as a simple version of the Linux environment (including root user rights, process space, user space, cyberspace, etc.) and applications running in it.

* * Warehouse [registry]

* Warehouse is a centralized place for storing image files. Sometimes the warehouse and the warehouse registration server (Registry) are confused, and there is no strict distinction. In fact, there are often multiple repositories on the warehouse registration server, and each warehouse contains multiple images, each with a different tag.

Warehouses are divided into public warehouses (Public) and private warehouses (Private).

The largest public repository is Docker Hub, which stores a large number of images for users to download. Domestic public warehouses, including Docker Pool, can provide mainland users with more stable and fast reading access.

After you have created your own image, you can use the push command to upload it to a public or private repository, so that when you download and use the image on another machine, you just need to pull it from the repository.

7. Docker actual combat

* system environment [recommended for docker operating environment when the kernel of linux is greater than 2.6]

[root@docker ~] # cat / etc/redhat-release CentOS Linux release 7.2.1511 (Core) [root@docker ~] # uname-r3.10.0-327.36.3.el7.x86_64

* docker service installation

[root@docker ~] # yum install docker

* start the docker service

[root@docker ~] # systemctl start docker.service

* View docker version information

[root@docker ~] # docker versionClient: Version: 1.12.6 API version: 1.24 Package version: docker-1.12.6-28.git1398f24.el7.centos.x86_64 Go version: go1.7.4 Git commit: Fri May 26 17:28:18 2017 OS/Arch: linux/amd64Server: Version: 1.12.6 API version: 1 .24 Package version: docker-1.12.6-28.git1398f24.el7.centos.x86_64 Go version: go1.7.4 Git commit: 1398f24/1.12.6 Built: Fri May 26 17:28:18 2017 OS/Arch: linux/amd64

* search for images on docker hub repository [search on docker.io by default]

Docker search image name: version number [default is latest if left empty]

INDEX: search sourc

NAME: image name

DESCRIPTION: description

STARS: number of downloads

OFFICIAL: is it official?

AUTOMATED: whether to automate or not

[root@docker] # docker search centosINDEX NAME DESCRIPTION STARS OFFICIAL AUTOMATEDdocker.io docker.io/centos The official build of CentOS. 3397 [OK] docker.io docker.io/jdeathe/centos-ssh CentOS-6 6.9 x86_64 / CentOS-7 7.3.1611 x8... 70 [OK] docker.io docker.io/nimmis/java-centos This is docker p_w_picpaths of CentOS 7 with dif... 26 [OK] docker.io docker.io/gluster/gluster-centos Official GlusterFS Image [CentOS-7 + Glu... 19 [OK]

* obtain (download) the image from the docker hub repository to the local library [download from docker.io by default]

Docker pull image name: version number [default is latest if left empty]

[root@docker ~] # docker pull centos

* View all images in the local library

Docker p_w_picpaths

[root@docker ~] # docker p_w_picpathsREPOSITORY TAG IMAGE ID CREATED SIZEdocker.io/centos latest 3bee3060bfc8 9 days ago 192.5 MB

* Export local library image

Docker save image name: version number > export file name

[root@docker ~] # docker save centos > centos.tar.gz

* Delete the local library image

Docker rmi image name: version number

[root@docker ~] # docker rmi centosUntagged: centos:latestUntagged: docker.io/centos@sha256:aebf12af704307dfa0079b3babdca8d7e8ff6564696882bcb5d11f1d461f9ee9Deleted: sha256:3bee3060bfc81c061ce7069df35ce090593bda584d4ef464bc0f38086c11371d

* Import the image file to the local library

Docker load < image file

[root@docker ~] # docker load < centos.tar.gz Loaded p_w_picpath: docker.io/centos:latest

* create a new container and run

When using docker run to create containers, standard operations for Docker to run in the background include:

* check whether the specified image exists locally. Download it from the public repository if it does not exist.

* create and start a container using an image

* assign a file system and hang it on a read-write layer outside the read-only mirror layer

* bridging a virtual interface to the container from the bridge interface configured by the host host

* configure an ip address from the address pool to the container

* execute user-specified applications

* the container is terminated after execution

Docker run [option....]

For example: run a container, specify the name as hello, and terminate the container after outputting hello

[root@docker ~] # docker run-- name hello centos echo "hello" hello

For example: start a container, specify the bash command, and go inside the container

-I: keep the standard input of the container open.

-t: let Docker assign a pseudo terminal and bind it to the standard input of the container

/ bin/bash: execute a command

[root@docker ~] # docker run-it centos / bin/bash [root@b4473c885f51 /] # pwd/

* exit does not close the container

Ctrl + p + Q

[root@f91270f431bd /] # [root@docker ~] #

* start the terminated container

Docker start Container name

[root@docker ~] # docker start hellohello

* run as daemon

More often, you need to have the Docker container run as a daemon in the background. This can be achieved by adding the-d parameter.

Docker run-d [opation...]

[root@docker] # docker run-- name daemon-d centos / bin/bash 6fd939dd05004e18248e04d10de88076c61878aea904093e24e122a907371234

* View running containers

Docker ps

[root@docker ~] # docker ps

* View all containers

[root@docker ~] # docker ps-aCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES65c0868177e7 centos "/ bin/bash" 34 seconds ago Exited (0) 32 seconds ago daemon

* stop the container that is running

Docker stop container name or unique container ID [Container ID is viewed through ps CONTAINER ID]

[root@docker ~] # docker stop daemondaemon

* Delete stopped containers

Docker rm container name or unique container ID [Container ID is viewed through ps CONTAINER ID]

[root@docker ~] # docker rm daemondaemon

8. Summary

In order to demand-driven technology, there is no difference in technology itself, only in business.

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