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

Important daily operation of Docker container

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

Share

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

I. Mapping port docker run-p port outside the container: the port in the container publishes a nginx application-[root@docker ~] # docker images # View Image REPOSITORY TAG IMAGE ID CREATED SIZEmyalpine latest_with_hello.txt 3ce9b8b899ba 17 hours ago 5.59MBnginx latest F7bb5701a33c 10 days ago 126MBalpine latest cc0abc535e36 2 weeks ago 5.59MBzhoumingkang/alpine v3.10.3 cc0abc535e36 2 weeks ago 5.59MBalpine 3.9.4 055936d39205 8 months ago 5.53MBhello-world latest Fce289e99eb9 12 months ago 1.84kB [root@docker ~] # docker run-- rm-d-- name mynginx-p80 rm 80 nginx:latest # run container 12f98b8cbbc8c918dce442c085b6e6a8e40df86a41d7016c8c8bfb1395b5bc90 [root@docker ~] # docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES12f98b8cbbc8 nginx:latest "nginx-g 'daemon of daemon of 6 seconds ago Up 4 seconds 0.0.0.0 seconds 80-> 80/tcp mynginx [root@docker ~] # netstat-tlunp | grep 80tcp6 0 0:: 80:: * LISTEN 10728/docker-proxy II. Mount the data volume docker run-v out-of-container directory: the in-container directory mounts the current host / root/html directory to the container / usr/share/nginx/html- [root@docker html] # docker run-- rm-d-- name mynginx1-p81Ranger 80-v/root/html:/usr/share/nginx/html nginx:latest # and mounts the local directory to the container 5b3ef0ed66d8927c6e3e502cc652243e81e94922f8b6310fabf9cb0ab8c1 [root @ docker html] # netstat-tlunp | Grep 81tcp6 0 0: 81: * LISTEN 11587/docker-proxy [root@docker html] # docker ps | grep mynginx15b3ef0ed66d8 nginx:latest "nginx-g 'daemon of …" 6 minutes ago Up 6 minutes 0.0.0.0 docker exec 81-> 80/tcp mynginx1 [root@docker html] # docker exec-ti 5b3ef0ed66d8 / bin/sh # enter the container # ls / usr/share/nginx/html # to see whether the host directory is mounted to index.html. Pass the environment variable docker run-e variable name = variable value to add the system variable mingkang_env=mingkang_test- [root@docker html] # docker run-ti-- rm-- name myalpine-e mingkang_env=mingkang_test alpine:latest / bin/sh/ # envHOSTNAME=b6dad57f224fSHLVL=1HOME=/rootmingkang_env=mingkang_test # added environment variable TERM=xtermPATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/binPWD=/ Note: for multiple environment variables Install tools in the current NGINX container, install the curl tool command-[root@docker html] # docker ps-aCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES5b3ef0ed66d8 nginx:latest "nginx-g 'daemon of …" 33 minutes ago Up 33 minutes 0.0.0.0 docker exec 81-> 80/tcp mynginx1 [root@docker html] # docker exec-ti mynginx1 / bin/bash root@5b3ef0ed66d8:/# apt-get updateroot@5b3ef0ed66d8:/# apt-get install-y curl # Container installs tool root@5b3ef0ed66d8:/# which curl/usr/bin/curl 5. Image encapsulate the container that just updated apt-get and install the curl tool, and submit it to docker hub. [root@docker html] # docker commit-p mynginx1 zhoumingkang/nginx:curl # generate a local image sha256:d1b81c37853c29e7069b5127e19e28f0eb964f7a5720a81880a1f3ecda4c88b4 [root@docker html] # docker imagesREPOSITORY TAG IMAGE ID CREATED SIZEzhoumingkang/nginx curl d1b81c37853c 6 seconds ago 152MBmyalpine latest_with_hello.txt 3ce9b8b899ba 24 hours ago 5.59MBnginx Latest f7bb5701a33c 10 days ago 126MBalpine latest cc0abc535e36 2 weeks ago 5.59MBzhoumingkang/alpine v3.10.3 cc0abc535e36 2 weeks ago 5.59MBalpine 3.9.4 055936d39205 8 months ago 5 .53MBhello-world latest fce289e99eb9 12 months ago 1.84kB [root@docker html] # docker push zhoumingkang/nginx:curl # push image to remote The push refers to repository [docker.io/zhoumingkang/nginx] edb65c87d072: Pushed 75248c0d5438: Mounted from library/nginx 49434cc20e95: Mounted from library/nginx 556c5fb0d91b: Mounted from library/nginx curl: digest: sha256:15a6e2920bc27d9a46a5025b938d54451bac6e499ae51c65cc812d9a193f8f59 size: 1160 [root@docker html] #

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