In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains the use of Docker images and containers, the content is clear, interested friends can learn, I believe it will be helpful after reading.
Mirror accelerator
It is sometimes difficult to pull an image from Docker Hub in China, so you can configure the image accelerator. Many domestic cloud service providers provide domestic accelerator services, such as:
NetEase Cloud Accelerator https://hub-mirror.c.163.com
Aliyun Accelerator (login account is required): https://cr.console.aliyun.com/cn-hangzhou/mirrors
All the major cloud service providers in China provide Docker image acceleration service. It is recommended to select the corresponding image acceleration service according to the cloud platform running Docker. For more information, please refer to the official documentation.
On CentOS7 systems, write the following in / etc/docker/daemon.json (create a new file if it does not exist)
[root@docker01 ~] # vim / etc/docker/daemon.json {"registry-mirrors": ["https://hub-mirror.c.163.com"]}
Note that you must make sure that the file conforms to the json specification, otherwise Docker will not start.
Then restart the service.
Systemctl daemon-reloadsystemctl restart docker
Check whether the accelerator is in effect
Execute the following command, and if you see the following from the result, the configuration is successful.
[root@docker01 ~] # docker info # displays the information of the whole system. Registry Mirrors: https://hub-mirror.c.163.com/Live Restore Enabled: falseWARNING: bridge-nf-call-iptables is disabledWARNING: bridge-nf-call-ip6tables is disabled
Dcoker mirroring operation
Note: the corresponding image needs to exist locally before Docker runs the container. If the image does not exist locally, Docker will download the image from the image repository.
Search search for images
[root@docker01] # docker search centosNAME DESCRIPTION STARS OFFICIAL AUTOMATEDcentos The official build of CentOS. 5934 [OK] ansible/centos7-ansible Ansible on Centos7 128 [OK] jdeathe/centos-ssh OpenSSH / Supervisor / EPEL/IUS/SCL Repos-… [OK] consol/centos-xfce-vnc Centos container with "headless" VNC session... 114 [OK] centos/mysql-57-centos7 MySQL 5.7 SQL database server 74.
Pull downloads images from the image center
# format: docker pull:, if there is no tag, default is latest [root@docker01 ~] # docker pull centos:latestlatest: Pulling from library/centos8a29a15cefae: Pull complete Digest: sha256:fe8d824220415eed5477b63addf40fb06c3b049404242b31982106ac204f6700Status: Downloaded newer image for centos:latest
Push push image to the image center
Format: docker push: [root@docker01 ~] # docker push registry.cn-beijing.aliyuncs.com/google_registry/centos:latest
Note: if you have any questions, you can ignore them first, and the article on building a private warehouse will explain it again.
Images lists images
[root@docker01 ~] # docker images # or docker image lsREPOSITORY TAG IMAGE ID CREATED SIZEcentos latest 470671670cac 2 months ago 237MB
Save image saved locally
# format: docker save-o | [root@docker01 docker_test] # docker save-o centos_docker_20200413.tar centos:latest [root@docker01 docker_test] # ll-htotal 234Mmurrw1 root root 234M Apr 13 16:21 centos_docker_20200413.tar
Rmi Delete Mirror
# format: docker rmi | [root@docker01 docker_test] # docker imagesREPOSITORY TAG IMAGE ID CREATED SIZEcentos latest 470671670cac 2 months ago 237MB [root@docker01 docker_test] # docker rmi 470671670cac # Delete image [root@docker01 docker_test] # docker imagesREPOSITORY TAG IMAGE ID CREATED SIZE
Load Import Image
# format: docker load-I [root@docker01 docker_test] # docker load-I centos_docker_ 20200413.tar [root @ docker01 docker_test] # docker images REPOSITORY TAG IMAGE ID CREATED SIZEcentos latest 470671670cac 2 months ago 237MB
Tag tag
# format: docker tag SOURCE_IMAGE [: TAG] TARGET_IMAGE [: TAG] [root@docker01 docker_test] # docker images REPOSITORY TAG IMAGE ID CREATED SIZEcentos latest 470671670cac 2 months ago 237MB [root@docker01 docker_test] # docker tag centos:latest centos:20200413 [root@docker01 docker_test] # docker images REPOSITORY TAG IMAGE ID CREATED SIZEcentos 20200413 470671670cac 2 months ago 237MBcentos latest 470671670cac 2 months ago 237MB
Use: give the docker image a new tag as needed.
Info displays the information of the whole system.
[root@docker01 ~] # docker info Containers: 0 Running: 0 Paused: 0 Stopped: 0Images: 1Server Version: overlay2 Backing Filesystem: xfs Supports d_type: true Native Overlay Diff: trueLogging Driver: json-fileCgroup Driver: cgroupfsPlugins: Volume: local Network: bridge host macvlan null overlay Log: awslogs fluentd gcplogs gelf journald json-file logentries splunk syslogSwarm: inactiveRuntimes: runcDefault Runtime: runcInit Binary: docker-initcontainerd version: 468a545b9edcd5932818eb9de8e72413e616e86erunc version: a592beb5bc4c4092b1b1bac971afed27687340c5init version: fec3683Security Options: seccomp Profile: defaultKernel Version: 3.10.0-1062.el7 .x86 _ 64Operating System: CentOS Linux 7 (Core) OSType: linuxArchitecture: x86_64CPUs: 2Total Memory: 1.777GiBName: docker01ID: XIHU:XNWU:II7A:YXUH:BOZ3:JSGG:J3P2:CU2Z:5QHA:5Y64:PZ4V:62DIDocker Root Dir: / var/lib/dockerDebug Mode (client): falseDebug Mode (server): falseRegistry: https://index.docker.io/v1/Labels:Experimental: falseInsecure Registries: 127.0.0.0/8Registry Mirrors: https://hub-mirror.c.163.com/Live Restore Enabled: falseWARNING: bridge-nf-call-iptables is disabledWARNING: bridge-nf-call-ip6tables is disabled
System Mirror Volume View
Another thing to note is that the mirror volumes in the docker image ls list are not the sum of all mirrored actual hard disk consumption. Because Docker mirrors are multi-tier storage structures and can be inherited and reused, different mirrors may share a common layer because they use the same underlying image. Because Docker uses Union FS, only one copy of the same layer needs to be saved, so the actual mirrored hard disk is likely to take up much less space than the sum of the image sizes in this list.
You can use the following command to easily view the space occupied by images, containers, and data volumes.
[root@docker01 docker_test] # docker system dfTYPE TOTAL ACTIVE SIZE RECLAIMABLEImages 20 440.1MB 440.1MB (100%) Containers 00B 0BLocal Volumes 00B 0BBuild Cache 00B 0B
Inspect displays the details of the image or container
# format: docker inspect | | [root@docker01 ~] # docker inspect centos:latest # display image details [root@docker01 ~] # docker inspect 67ba647b0151 # display container details
Dcoker container operation
Run creates a container
# format: docker run [OPTIONS] IMAGE [COMMAND] [ARG...] [root@docker01 ~] # docker run-I-t-- name centos01 centos:latest / bin/bash [root@f7c4da3cecad /] # # now you have entered the docker container [root@f7c4da3cecad /] # exit # exit the container, and the container will stop [normal] [root@docker01 ~] #
Parameter description:
-I interactive operation
-t assign a terminal
-- name of the container under which name is running
Last command to be executed by / bin/bash
Ps view container
[root@docker01 ~] # docker ps # View running containers CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES [root@docker01 ~] # [root@docker01 ~] # docker ps-a # View all containers, including CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMESf7c4da3cecad centos:latest "/ bin/bash" 4 minutes ago Exited (0) 36 seconds ago centos01 running and stopping
Start startup container
# format: docker start | [root@docker01 ~] # docker ps-aCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMESf7c4da3cecad centos:latest "/ bin/bash" 10 minutes ago Exited (0) 3 seconds ago centos01 [root@docker01 ~] # docker start f7c4da3cecad # launch container f7c4da3cecad [root@docker01 ~] # docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMESf7c4da3cecad centos:latest "/ bin/bash" 10 minutes ago Up 3 seconds centos01
Restart restart the container
# format: docker restart | [root@docker01 ~] # docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMESf7c4da3cecad centos:latest "/ bin/bash" 15 minutes ago Up 4 minutes centos01 [root@docker01 ~] # docker restart f7c4da3cecad # restart container f7c4da3cecad [root@docker01 ~] # docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMESf7c4da3cecad centos:latest "/ bin/bash" 15 minutes ago Up 1 second centos01
Stop stop Container
# format: docker stop | [root@docker01 ~] # docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMESf7c4da3cecad centos:latest "/ bin/bash" 3 hours ago Up 4 minutes centos01 [root@docker01 ~] # docker stop f7c4da3cecad # stop container f7c4da3cecad [root@docker01 ~] # docker ps-aCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMESf7c4da3cecad centos:latest "/ bin/bash" 3 hours ago Exited (0) 10 seconds ago centos01
Rm delete container
# format: docker rm | [root@docker01 ~] # docker ps-aCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMESf7c4da3cecad centos:latest "/ bin/bash" 3 hours ago Exited (0) 10 seconds ago centos01 [root@docker01 ~] # docker rm f7c4da3cecad # Delete a stopped container f7c4da3cecad
Note: if you want to force the deletion of a running container, use docker rm-f. However, forced deletion of containers is not recommended in the production environment to prevent erroneous deletion.
Rename rename Container
# format: docker rename CONTAINER NEW_ name [root @ docker01 ~] # docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES67ba647b0151 centos:latest "/ bin/bash" About a minute ago Up About a minute centos01 [root@docker01 ~] # docker rename 67ba647b0151 centos001 # container rename [root@docker01 ~] # docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES67ba647b0151 centos:latest "/ bin/bash" 2 minutes ago Up About a minute centos001
Exec enters the container or executes commands in the running container
Enter the container
[root@docker01 ~] # docker exec-it f7c4da3cecad bash [root@f7c4da3cecad /] #
Note: it is not recommended to enter the container through docker attach.
Let the specified container execute the command outside the container
# do not have the-t option, because there is no need to assign tty terminals [root@docker01] # docker exec-I f7c4da3cecad bash-c "ps-ef" UID PID PPID C STIME TTY TIME CMDroot 100 10:12 pts/0 00:00:00 / bin/bashroot 78 00 10:19? 00:00:00 ps-ef
Cp copies a file or directory
Copy the host file or directory into the docker container
[root@docker01] # docker exec-I 67ba647b0151 bash-c "ls-l / root" total 12 RW-1 root root 2366 Jan 13 21:49 anaconda-ks.cfg-rw-r--r-- 1 root root 435 Jan 13 21:49 anaconda-post.log-rw- 1 root root 2026 Jan 13 21:49 original-ks.cfg [root@docker01] # [root@docker01] # docker cp / usr/bin/telnet 67ba647b0151:/root / # copy files [root@docker01 ~] # docker cp / root/basedOptimi 67ba647b0151:/root/ # copy directory [root@docker01 ~] # docker exec-I 67ba647b0151 bash-c "ls-l / root" total 112 RW-1 root root 2366 Jan 13 21:49 anaconda-ks.cfg-rw-r--r-- 1 root root 435 Jan 13 21:49 anaconda-post.logdrwxr-xr-x 2 root root 30 Mar 8 19:59 basedOptimi- Rw- 1 root root 2026 Jan 13 21:49 original-ks.cfg-rwxr-xr-x 1 root root 101776 Aug 3 2017 telnet
Copy the files or directories in the docker container to the host
[root@docker01 ~] # docker cp 67ba647b0151:/root/original-ks.cfg / root/ # copy file [root@docker01 ~] # docker cp 67ba647b0151:/etc / root/ # copy directory
Logs view container log
[root@docker01 ~] # docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMESf7c4da3cecad centos:latest "/ bin/bash" 3 hours ago Up 1 second centos01# get container log [root@docker01] # docker logs-f-- tail 500 f7c4da3cecad.
Parameter description:
-f continuous printout
Tail 500print the last 500 lines of the log
Stats Container usage Resource Statistics
Can be used for monitorin
[root@docker01 ~] # docker stats | # continuous monitoring [root@docker01 ~] # docker stats-- no-stream | # instead of continuous monitoring, only the results returned for the first time are displayed
Processes running in the top container
[root@docker01 ~] # docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES67ba647b0151 centos:latest "/ bin/bash" 2 hours ago Up 2 hours centos001 # View the process information running in the container [root@docker01 ~] # docker top 67ba647b0151UID PID PPID C STIME TTY TIME CMDroot 3302 3285 0 21:13 pts/0 00:00:00 / bin/bash
Port container maps specific ports
Container mapping ports include random port mapping, specifying a single port mapping, and specifying multiple port mappings
Get the image
[root@docker01 ~] # docker pull registry.cn-beijing.aliyuncs.com/google_registry/nginx: 1.17 [root @ docker01 ~] # docker tag ed21b7a8aee9 nginx:1.17 [root@docker01 ~] # docker images | grep 'nginx'nginx 1.17 ed21b7a8aee9 2 weeks ago 127MBregistry.cn-beijing.aliyuncs.com/google_registry/nginx 1.17 ed21b7a8aee9 2 weeks ago 127MB
Map random port
[root@docker01] # docker run-d-P-- name nginx01 nginx:1.17e90c9faaf8e3387920dd9763bf5c7df9dd17856673868bb512cec78741ff71dc [root@docker01 ~] # docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMESe90c9faaf8e3 nginx:1.17 "nginx-g'daemon of …" 3 seconds ago Up 2 seconds 0.0.0.0 name nginx01 nginx:1.17e90c9faaf8e3387920dd9763bf5c7df9dd17856673868bb512cec78741ff71dc 1025-> 80/tcp nginx01
Description:
0.0.0.0 80/tcp 1025-> the front is the host port and the rear is the container port
Container log:
[root@docker01] # docker logs-f-- tail 500 nginx01
Browser access:
Map a single designated port
[root@docker01 ~] # docker run-d-p 81:80-- name nginx02 nginx:1.1704478222f0dc981883f25504164be3af7da49248886cee7386ccc89b80cc57a1 [root@docker01 ~] # docker ps | grep 'nginx02'04478222f0dc nginx:1.17 "nginx-g' daemon of..." 29 seconds ago Up 28 seconds 0.0.0.0 name nginx02 nginx:1.1704478222f0dc981883f25504164be3af7da49248886cee7386ccc89b80cc57a1 81-> 80/tcp nginx02
Browser access:
Map multiple designated ports
[root@docker01] # docker run-d-p 85:80-p 445 root@docker01 443-- name nginx03 nginx:1.175886e52ff8e934bc827c8d7753a532b9062bd045799d0658a008e371e6ecd09c [root@docker01 ~] # docker ps | grep 'nginx03'5886e52ff8e9 nginx:1.17 "nginx-g' daemon of..." 12 seconds ago Up 11 seconds 0.0.0.0 Docker 85-> 80/tcp, 0.0.0.0 80/tcp 445-> 443/tcp nginx03 after reading the above content, do you have a further understanding of the use of Docker images and containers? if you want to learn more, please follow the industry information channel.
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.