In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces "the corresponding operation introduction of the three concepts of Docker image, container and warehouse". In the daily operation, I believe that many people have doubts about the corresponding operation introduction of the three concepts of Docker image, container and warehouse. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about the corresponding operation introduction of the three concepts of Docker image, container and warehouse. Next, please follow the editor to study!
Mirror image
Image is a prerequisite for Docker to run the container.
Get the image docker pull NAME [: TAG] / / No TAG is specified. By default, select latest tag to run the image docekr run-t-I ubuntu / bin/bash to view the image information docker images
Add an image label
Docker tag ubuntu:latest my/ubuntu:latest
View image details
Docker inspect image iddocker inspect-f {{".Architecture"}} id / / query a certain item to search for an image docker search TERM--automated=false only shows automatically created images-- no-trunc=false output does not truncate display-- no-trunc=false 0 only shows images rated above the specified star delete image docker rmi IMAGE [IMAGE...] Where IMAGE can be tag or id
Delete a running image
Docker rmi-f ubuntu forced deletion (not recommended) recommended: 1. Delete the container; 2. Then use id to delete the image docker rm id docker rmi ubuntu to create a mirror
Create based on an existing image
The options for docker commit [OPTIONS] CONTAINER [REPOSITORY [: TAG]] include:-a meme talk authoring = "" author info-mmae talk message= "" submission info-pmai talk talk true to suspend the container when it is submitted
Here is a demonstration:
$winpty docker run-ti ubuntu bashroot@39b31ce63c14:/# touch testroot@39b31ce63c14:/# exit# view container id$ docker ps-aCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES39b31ce63c14 ubuntu "bash" 12 minutes ago Exited (0) 11 minutes ago Friendly_chebyshev$ docker commit-m "added a new file"-a "coderluo" 39b test:coderluosha256:489150941c65c552268ddacd10d9fe05c01e30c8c3bd111e4217d727e8f724c4
Import based on local template
You can import an image directly from an operating system template file. It is recommended to use the template provided by OpenVZ to create it. The download address is:
Https://wiki.openvz.org/Download/template/precreated
For example, when I download a ubuntu, I can import it using the following command:
[root@izwz909ewdz83smewux7a7z ~] # cat ubuntu-14.04-x86_64-minimal.tar.gz | docker import-ubuntu:14.04sha256:57a7c0bb864c4185d5d9d6eb6af24820595482b9df956adec5fde8d16aa9cb7c [root@izwz909ewdz83smewux7a7z ~] # docker images
Create based on Dockerfile
Save out and load images
You can use the docker save and docker load commands to save and load images
Save the image $docker imagesREPOSITORY TAG IMAGE ID CREATED SIZEmyubuntu coderluo 489150941c65 About an hour ago 64.2MBubuntu latest a2a15febcdf3 43 hours ago 64.2MBubuntu 14.04 271ca7812183 3 months ago 188MBchong@L MINGW64 ~ $docker save-o myubuntu _ 14.04.tar myubuntu:coderluo loads the image chong@L MINGW64 ~ $docker load
< myubuntu_14.04.tar上传镜像docker push NAME[:TAG]容器 容器就是镜像的一个运行实例,它带有额外的可写文件层 创建容器新建容器 使用 docker create 创建容器后市处于停止状态,可以使用 docker start 启动 docker create -it ubuntu:latest新建并启动容器root@ubuntu_server:/home/coderluo# docker run ubuntu /bin/echo 'i am coderluo'i am coderluo 等价于先 docker create 然后 docker start命令 docker run 需要执行的动作: 检查本地是否有对应的镜像,不存在就从共有仓库下载; 利用镜像创建并启动一个容器; 分配一个文件系统,并在只读的镜像层外面挂载一层可读写层; 从宿主机配置的网桥接口中桥接一个虚拟接口到容器中; 分配一个ip给容器; 执行用户指定的应用程序; 执行完毕后容器关闭; 接下来,我们打开一个bash终端,允许用户交互: docker run -ti ubuntu bash -t : 选项让Docker分配一个伪终端并绑定到容器的标准输入 -i : 让容器的标准输入保持打开 使用 exit 可以退出容器,退出后该容器就处于终止状态,因为对应Docker容器来说,当运行的应用退出后,容器也就没有运行的必要了; 守护态运行 比较常见的是需要Docker容器在后台以守护态 形式运行。 可以通过添加 -d 参数来实现: $ docker run -d ubuntu sh -c "while true; do echo hello world; sleep 1; done"caedc06b26723ec1aff794a053835d2b0b603702bea8a5bb3a39e97b0adf5654$ docker logs caehello worldhello worldhello worldhello worldhello worldhello world终止容器docker stop [-t|--time[=10]] 它首先会向容器发送SIGTERM信号,等待一段时间后(默认10s)。再发送SIGKILL信号终止容器。 注意: docker kill 会直接发送SIGKILL 来强行终止容器。 $ docker stop caecae 当Docker容器中运行的应用终结时,容器也自动终止。例如上面开启的终端容器,通过exit退出终端后,创建的容器也会终止。 可以使用 docekr ps -a -q 所有状态的容器ID信息。 $ docker ps -a -q90bcf718ad13caedc06b2672$ docker psCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMEScaedc06b2672 ubuntu "sh -c 'while true; …" 17 minutes ago Up About a minute epic_swartz$ docker restart caecae$ docker psCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMEScaedc06b2672 ubuntu "sh -c 'while true; …" 18 minutes ago Up 8 seconds epic_swartz进入容器 当容器后台启动,用户无法进入容器中,如果需要进入容器进行操作,则可以使用下面方法: attach命令$ docker run -idt ubuntub9953944f4cc4a17d09bba846d40eea25523098d188d44484f814132e3a04ae7$ docker psCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMESb9953944f4cc ubuntu "/bin/bash" 7 seconds ago Up 5 seconds laughing_chatterjee$ docker attach laughing_chatterjeeroot@b9953944f4cc:/# 缺点:当多个窗口同时attach到同一个容器中,所有窗口同步显示,一个阻塞则全部阻塞。 exec Docker 1.3 版本起引入一个可以直接在容器内执行命令的工具 exec。 进入之前创建的容器,并启动一个bash: $ docker exec -ti b99 bashroot@b9953944f4cc:/#nsenter 第三方支持,感兴趣可以自己google,个人感觉和exec差不多 删除容器 docker rm [OPTIONS] CONTAINER [CONTAINER...] -f,--force=false 强行终止并删除一个运行中的容器 -l,--link=false 删除容器的连接,但保留容器 -v,--volumes=false 删除容器挂载的数据卷 $ docker rm 90b90b$ docker rm b99Error response from daemon: You cannot remove a running container b9953944f4cc4a17d09bba846d40eea25523098d188d44484f814132e3a04ae7. Stop the container before attempting removal or force removechong@L MINGW64 ~$ docker rm -f b99b99导入和导出容器导出容器docker export CONTAINERdocker export cae >Test_for_run.tar
You can transfer the exported file to another machine and migrate the container directly through the import command.
Import Container
The exported file can be imported using the docker import command to become a mirror.
$cat Desktop/test_for_run.tar | docker import-test/ubuntu:v1.0 sha256:aa9dd6a88eb02d192c0574e1e2df171d0ec686a21048cba9a70fcd9ce3ba7d76 $docker imagesREPOSITORY TAG IMAGE ID CREATED SIZEtest/ubuntu v1.0 aa9dd6a88eb0 11 seconds ago 64.2MB
The difference between the docker load load image of the image module here and the previous image module is:
Docker import is used to import a container snapshot into the local mirror library, which discards all history and metadata information (that is, only saves the snapshot status of the container at that time), while the docker load command loads the image file to save the completed record, which is also large. And container snapshot import can reformulate metadata information such as labels.
Warehouse
A warehouse is a place where images are centrally stored
Many people tend to confuse warehouses and registration servers. The difference between a registration server and a warehouse is explained here.
The registration server is the place where repositories are stored. There can be multiple repositories on each server, and there are multiple images under each repository. For example, ubuntu is a repository, and there are many different versions of images below. The server he is in is the registration server.
Create and use private repositories create private repositories using registry images
You can use the official registry image to build a local private repository environment:
Docker run-d-p 5000UR 5000-v / opt/data/registry:/var/lib/registry registry
Parameter description:
-d, running in the background
-p, port mapping
-v, bind the / opt/data/registry of the host to / var/lib/registry to store the data in the local path. The default registry container contains the directory / var/lib/registry where the image files are stored.
After running, test all the images in our private repository:
$curl http:// warehouse host ip:5000/v2/_catalog% Total% Received% Xferd Average Speed Time Current Dload Upload Total Spent Left Speed100 20 100 20 00 20 00: 00:01 -:-0:00:01 160 {"repositories": []}
It is empty now because it has just been run and there is no mirror content in it.
Manage private warehouse images
Check the existing image on a test machine (non-warehouse machine). If there is no image currently, you can download it using docker pull.
Label the image
The format is: docker tag IMAGE [: TAG] [REGISTRYHOST/] [USERNAME/] NAME [: TAG]
Docker tag ubuntu:latest 192.168.137.200:5000/ubuntu:v1 $docker imagesREPOSITORY TAG IMAGE ID CREATED SIZE192.168.137.200:5000/ubuntu v1 a2a15febcdf3 3 days ago 64.2MB
192.168.137.200 the address and port of the private mirror registration server
Upload to the image server
$docker push 192.168.137.200:5000/ubuntuThe push refers to repository [192.168.137.200:5000/ubuntu] 122be11ab4a2: Pushed7beb13bce073: Pushedf7eae43028b3: Pushed6cebf3abed5f: Pushedv1: digest: sha256:ca013ac5c09f9a9f6db8370c1b759a29fe997d64d6591e9a75b71748858f7da0 size: 1152$ curl http://192.168.137.200:5000/v2/_catalog% Total% Received% Xferd Average Speed Time Current Dload Upload Total Spent Left Speed100 28 100 28 0 0 28 00: 00:01--:-0:00:01 198 {"repositories": ["ubuntu"]}
As shown in the curl command above, you can already see the image in the repository.
Test download image
$docker rmi-f image id # Delete local image $docker imagesREPOSITORY TAG IMAGE ID CREATED SIZE$ docker pull 192.168.137.200:5000/ubuntu:v1 # download private repository image v1: Pulling from ubuntu35c102085707: Pull complete251f5509d51d: Pull complete8e829fe70a46: Pull complete6001e1789921: Pull completeDigest: sha256:ca013ac5c09f9a9f6db8370c1b759a29fe997d64d6591e9a75b71748858f7da0Status: Downloaded newer image for 39.108.186.135:5000/ubuntu:v1 $docker images # View local mirror Like REPOSITORY TAG IMAGE ID CREATED SIZE192.168.137.200:5000/ubuntu v1 a2a15febcdf3 3 days ago 64.2MB
List all mirrors:
$curl 39.108.186.135:5000/v2/_catalog% Total% Received% Xferd Average Speed Time Current Dload Upload Total Spent Left Speed100 28 100 28 00 28 00: 00:01 -:-0:00:01 254 {"repositories": ["ubuntu"]}
All tag in an image repository:
$curl http://39.108.186.135:5000/v2/ubuntu/tags/list% Total% Received% Xferd Average Speed Time Current Dload Upload Total Spent Left Speed100 32 100 32 00 32 00: 00:01--:-0:00:01 128 {"name": "ubuntu", "tags": ["v1"]} The study of "introduction to the corresponding operation of the three concepts of Docker image, container and warehouse" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
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.