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

Docker container image management, port mapping, container interconnection

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

Each instruction in the hierarchical Dockerfile of docker mirroring will create a new mirror layer; the mirror layer will be cached and reused; when the instruction of Dockerfile is modified, the copied file changes, or the specified variable when building the mirror is different, the corresponding mirror layer cache will be invalidated; after the mirror cache of a certain layer expires, the mirror layer cache that follows it will be invalidated. The mirror layer is unchanged, if you add a file to one layer, and then delete it in the next layer Then the image still contains the file docker image is a standard format published by the application to support the creation of a running docker image of a docker container based on the existing image creation based on the local template creation based on the existing image creation based on the existing image package the program and running environment running in the container to generate a new image docker commit [option] container ID/ name warehouse name: [tag]-m Description information-a: author information-p: stop the operation of the container during generation based on the local template create a new image by importing the operating system template file use the wget command to import the local image after the import is successful, you can view the local image information based on Dockerfile create Dockerfile is a file composed of a set of instructions four parts of the basic image information maintainer information mirror operation instruction Execute instructions when the container starts using Dockerfile to create an image and run the dockerfile operation instruction in the container

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 / / package the programs and running environment 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 220MB creates [root@localhost ~] # mount.cifs / / 192.168.100.3/LNMP-C7 / mnt/ based on the local template and mounts the local template to the 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 based on the local template sha256: 487145d2411f0440c50fd93d0e8a9e27610d2de745a25d06955f21c80e65753a [root @ localhost mnt] # docker images / View / Mirror REPOSITORY TAG IMAGE ID CREATED SIZEdaoke new 487145d2411f 8 seconds ago 215MBcentos latest 0f3e07c0138f 3 months ago 220MB create [root@localhost ~] # mkdir apache/ / create a directory [root@localhost ~] # cd apache/ [root] based on the dockefile file @ localhost apache] # vim Dockerfile / / write a dockerfile file FROM centos / / based on the basic image MAINTAINER The porject / / maintain the user information of the image RUN yum-y update / / Image operation instructions install Apache software RUN yum-y install httpd / / install 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 at this time STATUS 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 / / the container is open. 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

As more and more image logs are created in public and private repositories, you need to have a place to store the images. This is the repository. At present, there are mainly two kinds of warehouses: public warehouse and private warehouse. The most convenient way 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: the public warehouse URL, the public warehouse / / the docker account / / the httpd:centos image that will be created. Upload it to the public repository you just applied for: docker tag httpd:centos xu/httpd:centosdocker push xu/httpd:centos private repository [root@localhost ~] # docker pull registry / / download registry image [root@localhost ~] # vim / etc/docker/daemon.json {"insecure-registries": ["192.168.13.128PV5000"] / / specify warehouse address and port number "registry-mirrors": ["https://3a8s9zx5.mirror.aliyuncs.com"] / / 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 / / create 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 image [root@localhost ~] # curl-XGET http://192.168.13.128:5000/v2/_catalog / / get private There is a list of repositories {"repositories": ["httpd"]} [root@localhost ~] # docker pull 192.168.13.128:5000/httpd / / download Docker network communications through private repositories docker provides a mechanism for mapping container ports to hosts 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. In essence, the port of the host is mapped to the container, so that the external network can access the services in the container by accessing the port of the host. [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

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

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