In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/03 Report--
Blog outline:
1. Brief introduction to docker. 2. Three core concepts of docker
1. Mirror image
2. Container
3. Warehouse 3. Basic operation of installation and docker
1. Installation and startup
2. Mirror operation of docker
3. Container operation of docker I. introduction to docker
Docker as the most popular project in the open source community, it is an open source tool to run applications in the Linux container, is a lightweight "virtual machine", all the source code of docker is maintained in https://github.com/docker, its official website is: https://www.docker.com.
The reason why docker has many advantages is inseparable from the characteristics of operating system virtualization. Traditional virtual machines need additional hypervisors and virtual machine operating system layers, while docker implements virtualization directly above the operating system level. The working diagram of the two is as follows:
The differences between a docker and a virtual machine are as follows:
2. Three core concepts of docker. 1. Mirroring
A docker image is the basis for creating a container, similar to a virtual machine snapshot, which can be understood as a read-only template for the docker container engine, for example, an image can be a complete centos operating system environment, called a centos image, an application with MySQL installed, called a MySQL image, and so on.
Docker provides a simple mechanism to create and update existing images, and we can also download existing application images from the Internet to use them directly.
2. Container
The container for docker is a running instance created from an image that can be started, stopped, and deleted. Each container created is an isolated and invisible platform to ensure security. The container can be regarded as a simple version of Linux environment. Docker uses containers to run and isolate applications.
3. Warehouse
Docker repositories are used to save images. After creating your own image, you can use the push command to upload it to a public or private repository, so that the next time you want to use the image on another machine, you just need to pull it from the warehouse and remove it.
The warehouse registration server is the place where the warehouse is stored, which contains multiple warehouses, each warehouse centrally stores a certain type of image, and uses different tags to distinguish them. At present, the largest public repository is docker hub, which stores a large number of images for users to download.
The default storage directory of docker is stored here in the images, containers, logs and other contents of / var/lib/docker,docker. You can use large-capacity partitions to store these contents, and generally choose to establish LVM logical volumes, so as to avoid the problem of insufficient storage directory capacity during docker operation.
3. Basic operation of installation and docker 1. Installation and startup
When installing, you must ensure that the server is configured to have access to the Internet, or you can configure your own local yum source.
[root@localhost ~] # yum-y install docker # directly install [root@localhost ~] # systemctl start docker # start docker service [root@localhost ~] # systemctl enable docker # set to boot self-boot [root@localhost ~] # docker version # View installed docker version 2, image operation of docker (1) find an image
Before docker runs the container, the corresponding image needs to exist locally. If no local image exists, docker will try to find it from the default image repository https://hub.docker.com/.
[root@localhost ~] # docker search dhcp # search for image INDEX NAME DESCRIPTION STARS OFFICIAL AUTOMATEDdocker.io docker.io/networkboot/dhcpd Suitable for running a DHCP server for you... with DHCP as keyword 40 [OK] docker.io docker.io/joebiellik/dhcpd DHCP server running on Alpine Linux 14 [OK] docker.io docker.io/gns3/dhcp A DHCP container for GNS3 using dnsmasq 2 [OK] docker.io docker.io/instantlinux/dhcpd-dns-pxe Serve DNS DHCP and TFTP from a small Alpi... 2 [OK] docker.io docker.io/ictu/dhcpd-tftpd dhcpd tftpd container 1 [OK]. # omit part of the content
Many images containing the DHCP keyword are returned. The returned information includes image name (NAME), description (DESCRIPTION), star (STARS), whether it is officially created (OFFICIAL), and whether it is actively created (AUTOMATED). The default output is sorted by star rating, indicating the popularity of the image. When downloading an image, you can refer to this item. The higher the star, the more popular it is. Whether it is an official image refers to whether the image is created and maintained by the official project team. Generally, the image maintained by the official project team uses a single word as the image name, which is called the basic image or the root image. For example, the named image of / reinblau/dhcp means that the image is created and maintained by the user reinblau of docker hub, with the user name prefixed. Whether to actively create a resource means whether the user is allowed to verify the source and content of the image.
(2) download the image
If you find an image that meets your needs, you can use the docker pull command to download the image from the network and use it locally.
Command format: docker pull warehouse name [: label]
For docker images, if you do not specify a label when downloading the image, the latest version of the image in the repository will be downloaded by default, that is, you can select the label latest, or you can download a specific version of the image through the specified tag. The tag here is used to distinguish between mirrored versions.
Download an image as follows
[root@localhost ~] # docker pull docker.io/networkboot/dhcpd # download a queried image [root@localhost ~] # docker images # query the downloaded image REPOSITORY TAG IMAGE ID CREATED SIZEdocker.io/networkboot/dhcpd latest 52cbff801df2 5 months ago 105 MB from the echo information can be found To read the following information: # REPOSITORY: the repository to which the image belongs # TAG: tag information of the image, marking different images in the same repository; # IMAGE ID: the unique ID number of the image, which uniquely identifies the image; # CREATED: the time when the image was created; # SIZE: users of the image size can also obtain the details of the image based on the image's unique ID ID number. The command is as follows: [root@localhost ~] # docker inspect 52cbff801df2 # get the details of the image # the details of the image include creation time, system version, hostname, domain name, user, volume, label, operating system, device ID and other information. # in order to use this image in subsequent work, you can use the docker tag command to add a new tag to the local image. # command format: docker tag name: [label] New name: [new tag] The specific operations are as follows: [root@localhost ~] # docker tag docker.io/networkboot/dhcpd dchp:dhcp # change the name and label [root@localhost ~] # docker imagesREPOSITORY TAG IMAGE ID CREATED SIZEdchp dhcp 52cbff801df2 5 months ago 105MBdocker.io/networkboot/dhcpd latest 52cbff801df2 5 months ago 105 MB (3) Delete Mirror
You will find that the original image is still there, so try to delete the original image.
Use the docker rmi command to delete redundant images, specify a label to delete them, or specify ID to delete images
Delete image command format: docker rmi repository name: tag or docker rmi image ID number. When an image has multiple tags, the specified tag only deletes the specified tags in multiple tags of the image and will not affect the image file, which is equivalent to deleting only one tag of the image. But when there is only one tag left in the image, you should pay attention, and then use the delete command to delete the image completely.
[root@localhost ~] # docker rmi docker.io/networkboot/dhcpd # Delete the original image tag Untagged: docker.io/networkboot/dhcpd:latestUntagged: docker.io/networkboot/dhcpd@sha256:fdc7ff6f265249a104f32f1d7aed0aedaf2f2fc62ea10eebf596e2af3b670477
When using the docker rmi command followed by the ID number of the image, you must make sure that the image is not used by the container. When deleting, the system will delete all tags pointing to the image, and then delete the image file itself. If the image is already used by the container, the correct way is to delete all containers that depend on the image, and then delete the image.
(4) Export image
When you need to migrate an image from one machine to another, you need to save the image to a local file. This process is called exporting the image. You can use the docker save command to save out, and then you can copy the file to another machine.
Command format: docker save-o save image as local file
As follows:
[root@localhost ~] # docker images # get the image name and label REPOSITORY TAG IMAGE ID CREATED SIZEdchp dhcp 52cbff801df2 5 months ago 105 MB [root@localhost ~] # docker save-o dhcptest dchp:dhcp # Export as a local image [root@localhost ~] # du-sh dhcptest # will be exported to the local current working directory 103m dhcptest (5) to load the image
To copy the exported image from machine A to machine B, you need to use the image on machine B, and you can import the export file into the image library on machine B. this process is called loading the image.
The command format is (load the image guide local mirror library from the file dhcp):
[root@localhost ~] # docker load-input dhcp# or [root@localhost ~] # docker load
< dhcp(6)上传镜像 本地存储的镜像越来越多,就需要指定一个专门存放这些镜像的地方--仓库,比较简单的就是公共仓库,默认上传到dockerhub官方仓库,需要注册使用公共仓库的账号,可以使用docker login命令来输入用户名,密码和邮箱来完成注册和登录,在上传镜像之前还需要对本地镜像添加新的标签,然后再使用docker push命令进行上传。 命令格式:docker push 仓库名称:标签 [root@localhost ~]# docker loginLogin with your Docker ID to push and pull images from Docker Hub. If you don't have a Docker ID, head over to https://hub.docker.com to create one.Username: ljztest #输入注册的用户名Password: #输入密码Login Succeeded #提示登录成功[root@localhost ~]# docker push docker.io/ljztest/dhcp #在这里登录上传时,报错,发现是因为镜像的仓库名称有问题,根据提示改了下仓库名称,就上传成功了The push refers to a repository [docker.io/ljztest/dhcp]8d3d1c857813: Pushed 37ee4253c76e: Pushed b57c79f4a9f3: Pushed d60e01b37e74: Pushed e45cfbc98a50: Pushed 762d8e1a6054: Pushed testdhcp: digest: sha256:fdc7ff6f265249a104f32f1d7aed0aedaf2f2fc62ea10eebf596e2af3b670477 size: 15693、docker的容器操作 容器是docker的另一个核心概念,简单来说,容器是镜像的一个运行实例,是独立运行的一个或一组应用及它们所必需的运行环境,包括文件系统、系统类库、shell环境等。镜像是只读模板,而容器会给这个只读模板一个额外的可写层。 (1)容器的创建与启动 docker的创建就是将镜像加载到容器的过程,docker的容器十分轻量级,用户可以随时创建或者删除。新创建的容器默认处于停止状态,不运行任何程序,需要在其中一个发起一个进程来启动容器,这个进程是该容器的唯一进程,所以当该进程结束的时候,容器也会完全停止。停止的容器可以重新启动并保留原来的修改。可以使用docker create 命令新建一个容器。 1)创建容器 命令如下(-i:表示让容器的输入保持打开,就是容器一直运行;-t:是让docker分配一个伪终端): [root@localhost ~]# docker create -it dchp:dhcp /bin/bash #创建一个容器,并指定伪终端2304f92a815800305804987bcb2ee20aca5f4d651d577427c476554d54171f2d#如果此刻创建容器命令报错"WARNING:IPv4 forwarding is disabled.Network will bot#work.",就使用vim编辑器打开/usr/lib/sysctl.d/00-system.conf文件,在其中添加#net.ipv4.ip_forward=1,然后使用systemctl start network命令重启网络服务即可[root@localhost ~]# docker ps -aCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES2304f92a8158 dchp:dhcp "/entrypoint.sh /b..." 8 minutes ago Created naughty_perlman#输出的信息显示容器的ID号、加载的镜像、运行的程序、创建时间、目前所处的状态、端口映射、容器名称等。#上面查出的状态一栏是create表示当前的容器是新创建的并处于停止状态。 2)启动和停止容器 [root@localhost ~]# docker ps -a #先查出容器的ID号CONTAINER ID IMAGE COMMAND CREATE2304f92a8158 dchp:dhcp "/entrypoint.sh /b..." 10 min[root@localhost ~]# docker start 2304f92a8158 #启动时,需指定容器的ID号2304f92a8158[root@localhost ~]# docker ps -a #再查询容器的状态,会发现状态栏变成了UPCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES2304f92a8158 dchp:dhcp "/entrypoint.sh /b..." 23 minutes ago Up 42 seconds naughty_perlman[root@localhost ~]# docker stop 2304f92a8158 #停止这个容器2304f92a8158[root@localhost ~]# docker ps -a #再次查看状态,会发现状态栏变成了exitedCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES2304f92a8158 dchp:dhcp "/entrypoint.sh /b..." About an hour ago Exited (0) 4 seconds ago naughty_perlman 3)进入容器 [root@localhost ~]# docker start 2304f92a8158 #再次启动这个容器[root@localhost ~]# docker exec -it 2304f92a8158 /bin/bash #进入这个容器root@2304f92a8158:/# ls #查看这个容器的根目录,可以看到进入容器后命令提示符发生了变化bin dev etc lib media opt root sbin sys usrboot entrypoint.sh home lib64 mnt proc run srv tmp varroot@2304f92a8158:/# exit #退出这个容器exit[root@localhost ~]# (2)容器的导出与导入[root@localhost ~]# docker ps -a #查询容器的ID号CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES2304f92a8158 dchp:dhcp "/entrypoint.sh /b..." About an hour ago Up 6 minutes naughty_perlman[root@localhost ~]# docker export 2304f92a8158>Centos7dhcp # exports to the current working directory and defines the name as centos7dhcp [root@localhost ~] # ls # to view the exported file. The following is marked red: the exported file anaconda-ks.cfg 'centos7dhcp' dhcptest initial-setup-ks.cfg# copies the exported file to another server, and then uses the docker import command to import Become a mirror [root@localhost ~] # scp root@192.168.1.1:/root/centos7dhcp / tmp # copy on another server root@192.168.1.1's password: # enter the peer's user password centos7dhcp 100% 84MB 95.2MB/s 00:00 [root@localhost ~] # cd / tmp [root@localhost tmp] # ls # make sure that centos7dhcp. # omit part of the content [root@localhost tmp] # cat centos7dhcp | docker import-centos7:dhcp # Import file centos7dhcp to become a local image sha256: e016fa46360492daa9323a0d35bccec76610433f03ba9171fe6d9a5500f823ffroot @ localhost tmp] # docker images | grep centos7 # confirm that the image was imported successfully centos7dhcp e016fa463604 14 minutes ago 84.7 MB (3) container deletion
You can use the docker rm command to delete a container that has been terminated.
[root@localhost ~] # docker ps-a # still needs to find out the container's IDCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES2304f92a8158 dchp:dhcp "/ entrypoint.sh / b." About an hour ago Up 35 minutes naughty_ perlman [root @ localhost ~] # docker stop 2304f92a8158 # stop the container 2304f92a8158 [root@localhost ~] # docker rm 2304f92a8158 # delete the container 2304f92a8158 before deleting the container
If you delete a running container, you can add the-f option to force the deletion, but it is recommended to stop the container before deleting it.
-this is the end of this article. Thank you for reading-
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.