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 > Servers >
Share
Shulou(Shulou.com)06/03 Report--
This article introduces mirror management, port mapping and container interconnection in Docker. Most of the knowledge points are often used by everyone, so I will share them for you as a reference. Let's follow the editor and have a look.
Layering of docker Mirror
Each instruction in Dockerfile creates a new mirror layer
The mirror layer will be cached and reused
When the Dockerfile instruction is modified, the copied file changes, or the specified variable when building the image is different, the corresponding mirror layer cache will be invalidated.
After the mirror cache of a certain layer expires, the mirror layer cache behind it will fail.
The mirror layer is unchanged, and if you add a file to one layer and then delete it in the next layer, the file is still included in the image
Docker image is a standard format for application release to support the running docker image of a docker container. Create a docker image based on an existing image, create a local template, create a dockerfile based on an existing image, package the programs and running environments running in the container to generate a new image docker commit [options] Container ID/ name repository name: [tag]-m: description information-a: author's letter Information-p: stop the operation of the container during the generation process based on the local template to create a new image by importing the operating system template file and use the wget command to import the local image. After the local image is successfully imported, you can view the local image information. Creating Dockerfile based on Dockerfile is a file composed of a set of instructions. Four parts of the Dockerfile structure: basic image information Maintainer information; mirror operation instructions; execute instructions when the container starts; use Dockerfile to create images and run dockerfile instructions in the container
one, Create a container based on an existing image [root@localhost ~] # docker pull centos # # download an image [root@localhost ~] # docker create-it centos / bin/bash # # create a container based on a centos image [root@localhost ~] # docker ps-a # # View container information CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES30d395e63fc3 centos "/ bin/bash" 7 seconds ago Created inspiring_ Germains [root @ localhost ~] # docker commit-m "new"-a "daoke" 30d395e63fc3 daoke:centos## packages the programs and running environment running in the container to generate a new image sha256:66d76f9225b94ce6156db953bd16c384f74067f981d45bee99340f3a965506d3 [root@localhost ~] # docker images # # View the image REPOSITORY TAG IMAGE ID CREATED SIZEdaoke Centos 66d76f9225b9 10 seconds ago 220MBcentos latest 0f3e07c0138f 3 months ago 220MB2 Create [root@localhost ~] # mount.cifs / / 192.168.100.3/LNMP-C7 / mnt/ # # based on the local template mount the local template to Linux Password for root@//192.168.100.3/LNMP-C7: [root@localhost ~] # cd / mnt # # change the directory to / mnt [root@localhost docker] # lsdebian-7.0-x86-minimal.tar.gz [root@localhost mnt] # cat debian-7. 0-x86-minimal.tar.gz | docker import-daoke:new## create an image sha256 based on the local template: 487145d2411f0440c50fd93d0e8a9e27610d2de745a25d06955f21c80e65753a [root @ localhost mnt] # docker images # # View the image REPOSITORY TAG IMAGE ID CREATED SIZEdaoke new 487145d2411f 8 seconds ago 215MBcentos latest 0f3e07c0138f 3 months ago 220MB3 Create a directory based on dockefile file [root@localhost ~] # mkdir apache # # create a directory [root@localhost ~] # cd apache/ [root@localhost apache] # vim Dockerfile # # write a dockerfile file FROM centos # # basic image MAINTAINER The porject # # maintain the user information of the image RUN yum-y update # # mirror Install the Apache software RUN yum-y install httpd # # install the Apache service EXPOSE 80 # # Open port 80 ADD index.html / var/www/html/index.html # # copy the URL home file ADD run.sh / run.sh # # copy the execution script to the image RUN chmod 755 / run.shCMD ["/ run.sh"] # # execute script [root@localhost apache] # vim run.sh # # Edit run.sh script #! / bin/bashrm-rf / run/httpd/* # # clear cache exec / usr/sbin/apachectl-D FOREGROUND # # execute apache [root@localhost apache] # echo "this is test web" > index.html # # create page information [root@localhost apache] # lsDockerfile index.html run.sh [root @ localhost apache] # docker build-t httpd:centos. # # create an image [root@localhost apache] # docker imagesREPOSITORY TAG IMAGE ID CREATED SIZEhttpd centos b267aaf2c395 22 seconds ago 401MB [root@localhost apache] # docker ps-a # # No container generates CONTAINER ID IMAGE COMMAND CREATED STATUS at this time PORTS NAMES [root@localhost apache] # docker run-d-p 1234Mun80 httpd:centos # # create a mapping Create a container 34c424efdab9e381116de697c4971200b1564b1e38644407cc58d5ba8923a0ea [root@localhost apache] # docker ps-a # # Container is open, and 1234 is an external port 80 is the internal port CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES34c424efdab9 httpd:centos "/ run.sh" 9 seconds ago Up 7 seconds 0.0.0.0 seconds ago Up 1234-> 80/tcp great_williamson## is accessed by browser
Public warehouse and private warehouse
As more and more mirror logs are created, you need to have a place to store the images, which is the repository. At present, there are mainly two kinds of warehouses: public warehouse and private warehouse. The most convenient thing is to use the public warehouse to upload and download images. You don't need to register to download the images in the public warehouse, but you need to register for uploading: public warehouse URL.
1. Public warehouse # # you need to register a docker account # # the httpd:centos image will be created. Upload to the public warehouse you just applied for: docker tag httpd:centos xu/httpd:centosdocker push xu/httpd:centos2 Private repository [root@localhost ~] # docker pull registry # # download registry image [root@localhost ~] # vim / etc/docker/daemon.json {"insecure-registries": ["192.168.13.128 docker 5000"], # # specify warehouse address and port number "registry-mirrors": ["root@localhost # # Image acceleration} [root@localhost ~] # systemctl stop docker # # stop docker" Open docker [root@localhost ~] # systemctl start docker [root@localhost ~] # docker create-it registry / bin/bash # # create registry image container 209dadd90f5c555ba328fae5763a61ae5fe4489acc4bfb945a99bb2307a9f139 [root@localhost ~] # docker ps-a # # View container CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES209dadd90f5c registry "/ entrypoint.sh / bin …" 4 seconds ago Created admiring_dewdney34c424efdab9 httpd:centos "/ run.sh" 13 minutes ago Exited (137) 35 seconds ago great_ Williamson [root @ localhost] # docker start 209dadd90f5c # # Open container 209dadd90f5c [root@localhost] # docker run-d-p 5000-v / data/ Registry:/tmp/registry registry## creates mapped ports and data volumes Host office / data auto mount container key / tmpfd4185499dfa29f1a1133f59b706a5524572ae3f22140137214ab4c8212ea8a4 [root@localhost ~] # docker images # # check the current image REPOSITORY TAG IMAGE ID CREATED SIZEhttpd centos b267aaf2c395 17 minutes ago 401MBcentos latest 0f3e07c0138f 3 months ago 220MBregistry Latest f32a97de94e1 10 months ago 25.8MB [root@localhost ~] # docker tag httpd:centos 192.168.13.128:5000/httpd # # modify the tag [root@localhost ~] # docker push 192.168.13.128:5000/httpd # # upload the image [root@localhost ~] # curl-XGET http://192.168.13.128:5000/v2/_catalog # # get the list of private repositories {"repositories": ["httpd"]} [root@localhost ~] # docker pull 192.168.13.128:5000/httpd # # download Docker network communication through private warehouse docker provides a mechanism for mapping container ports to host and container interconnection to provide network services for containers. Port mapping
Docker provides a port mapping mechanism to provide services in the container to external network access, which essentially maps the port of the host to the container, so that the external network accesses the port of the host and can access the services in the container.
1. Port mapping [root@localhost ~] # docker run-d-P nginx # # randomly designated port [root@localhost ~] # docker ps-a # # View container CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMESbcd11c99804e nginx "nginx-g 'daemon of …" 13 seconds ago Up 13 seconds 0.0.0.0 80/tcp## access port 32768 using a browser
[root@localhost ~] # docker run-d-p 32000 nginx 80 nginx # # designated port # # access port 32000 using browser
two, Container interconnection (using centos image) [root@localhost ~] # docker run-itd-P-- name web1 centos / bin/bash## create web1 container 87c58af3100fbc112bf344a421942dd53451c0c663b697a55a8d410868f314bf [root@localhost ~] # docker run-itd-P-- name web2-- link web1:web1 centos / bin/bash## create web2 connection web1 container 7a84075802b5689912c323196b5af398fb5912316efda014921c0e23d3e9cdd2 [root@localhost ~] # docker ps-a # # View container information CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES7a84075802b5 centos "/ bin/bash" 6 seconds ago Up 5 seconds web287c58af3100f centos "/ bin/bash" 42 seconds ago Up 41 seconds Web1 [root@localhost ~] # docker exec-it 7a84075802b5 / bin/bash # # enter the web2 container [root@7a84075802b5 /] # pingweb1 # # pingweb1 to see if there is interconnection between PING web1 (172.17.0.5) 56 (84) bytes of data.64 bytes from web1 (172.17.0.5): icmp_seq=1 ttl=64 time=0.090 ms64 bytes from web1 (172.17.0.5): icmp_seq=2 ttl=64 time=0.089 ms
These are the details of image management, port mapping and container interconnection in Docker. Have you learned anything after reading it? If you want to know more about it, you are welcome to follow the industry information!
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.