• Docker 镜像拉取


    Docker

    二、安装镜像


    2.1 安装Nginx

    # 搜索Nginx
    [root@vinjcent ~]# docker search nginx
    
    # 查看你镜像
    [root@vinjcent ~]# docker images
    REPOSITORY   TAG       IMAGE ID       CREATED        SIZE
    nginx        latest    0e901e68141f   2 weeks ago    142MB
    centos       latest    5d0da3dc9764   9 months ago   231MB
    
    # 开启宿主机的3344端口
    [root@vinjcent ~]# firewall-cmd --zone=public --add-port=3344/tcp --permanent
    [root@vinjcent ~]# systemctl restart firewalld.service
    [root@vinjcent ~]# firewall-cmd --list-ports
    [root@vinjcent ~]# docker run -d  --name nginx01 -p 3344:80 nginx
    
    ### 运行测试
    # -d 后台运行
    # --name 给容器命名
    # -p 宿主机端口:容器内部端口
    [root@vinjcent ~]# curl localhost:3344
    <!DOCTYPE html>
    <html>
    <head>
    <title>Welcome to nginx!</title>
    <style>
    html { color-scheme: light dark; }
    body { width: 35em; margin: 0 auto;
    font-family: Tahoma, Verdana, Arial, sans-serif; }
    </style>
    </head>
    <body>
    <h1>Welcome to nginx!</h1>
    <p>If you see this page, the nginx web server is successfully installed and
    working. Further configuration is required.</p>
    
    <p>For online documentation and support please refer to
    <a href="http://nginx.org/">nginx.org</a>.<br/>
    Commercial support is available at
    <a href="http://nginx.com/">nginx.com</a>.</p>
    
    <p><em>Thank you for using nginx.</em></p>
    </body>
    </html>
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44

    端口暴露的概念

    在这里插入图片描述

    在这里插入图片描述

    # 交互模式进入容器
    [root@vinjcent ~]# docker exec -it nginx01 /bin/bash
    root@e5347a513358:/# whereis nginx
    nginx: /usr/sbin/nginx /usr/lib/nginx /etc/nginx /usr/share/nginx
    root@e5347a513358:/# cd /etc/nginx
    root@e5347a513358:/etc/nginx# 
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6

    问题每次改动 Nginx 配置文件,都需要进入容器内部,十分麻烦!要是可以在容器外部提供一个映射路径,达到在容器内修改文件的效果,那么容器内部就可以自动修改 -v 数据卷

    2.2 安装Tomcat

    # 官方的使用
    docker run -it --rm tomcat:9.0
    
    # 我们之前的启动都是后台运行,停止了容器之后,容器还是可以查到	docker run -it --rm   ===>   一般用来测试,用完旧删除
    
    # 下载再启动
    docker pull tomcat:9.0
    
    # 查看
    [root@vinjcent ~]# docker images
    REPOSITORY   TAG       IMAGE ID       CREATED        SIZE
    tomcat       9.0       ae6026892279   5 days ago     680MB
    nginx        latest    0e901e68141f   2 weeks ago    142MB
    centos       latest    5d0da3dc9764   9 months ago   231MB
    
    # 启动运行
    [root@vinjcent ~]# docker images
    REPOSITORY   TAG       IMAGE ID       CREATED        SIZE
    tomcat       9.0       ae6026892279   5 days ago     680MB
    nginx        latest    0e901e68141f   2 weeks ago    142MB
    centos       latest    5d0da3dc9764   9 months ago   231MB
    [root@vinjcent ~]# docker run -d -p 3355:8080 --name tomcat01 ae6026892279
    
    # 测试访问没有问题
    
    # 进入容器
    [root@vinjcent ~]# docker exec -it tomcat01 /bin/bash
    
    # 发现问题: 1、Linux命令少了	2、没有webapps(是空的)   ===>   阿里云镜像的原因,默认是最小镜像,所有不必要的都剔除掉
    # 保证最小的可运行环境
    
    # 将当前容器中的文件夹 webapps.dist/ 下的所有文件复制到 webapps/ 下
    root@fe4bc497e6e0:/usr/local/tomcat# cp -r webapps.dist/* webapps
    root@fe4bc497e6e0:/usr/local/tomcat# cd webapps
    root@fe4bc497e6e0:/usr/local/tomcat/webapps# ls
    ROOT  docs  examples  host-manager  manager
    
    # 再次在本地访问
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38

    在这里插入图片描述

    在这里插入图片描述

    2.3 部署 ES + Kibana

    # es 暴露的端口很多
    # es 十分的耗内存
    # es 的数据一般需要防止安全目录,挂载
    
    # --net somenetwork   网络配置
    docker run -d --name elasticsearch --net somenetwork -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" elasticsearch:tag
    
    # 启动 elasticsearch
    docker run -d --name elasticsearch -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" elasticsearch:7.17.4
    
    # 启动了 elasticsearch就卡了
    # es 是十分耗内存的
    [root@vinjcent ~]# docker stats   # 查看docker容器CPU的运行效率
    
    # 测试es是否成功
    [root@vinjcent ~]# curl localhost:9200
    {
      "name" : "6dfb9c60988f",
      "cluster_name" : "docker-cluster",
      "cluster_uuid" : "CgNbOfhfQbWi03Fra_w6rg",
      "version" : {
        "number" : "7.17.4",
        "build_flavor" : "default",
        "build_type" : "docker",
        "build_hash" : "79878662c54c886ae89206c685d9f1051a9d6411",
        "build_date" : "2022-05-18T18:04:20.964345128Z",
        "build_snapshot" : false,
        "lucene_version" : "8.11.1",
        "minimum_wire_compatibility_version" : "6.8.0",
        "minimum_index_compatibility_version" : "6.0.0-beta1"
      },
      "tagline" : "You Know, for Search"
    }
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34

    在这里插入图片描述

    # 增加内存限制,修改配置文件 -e 环境配置修改
    docker run -d --name elasticsearch02 -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" -e ES_JAVA_OPTS="-Xms64m -Xmx512m" elasticsearch:7.17.4
    
    # 警告
    WARNING: IPv4 forwarding is disabled. Networking will not work.
    
    
    # 查看状态 docker stats
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8

    装完了Docker,然后启动镜像,发现没有网络,而且不能ifconfig,因网桥配置完后,需要开启转发,不然容器启动后,就会没有网络,配置/etc/sysctl.conf,添加net.ipv4.ip_forward=1即可,操作如下:

    vim /etc/sysctl.conf
     
    #配置转发
    net.ipv4.ip_forward=1
     
    #重启服务,让配置生效
    systemctl restart network
     
    #查看是否成功,如果返回为“net.ipv4.ip_forward = 1”则表示成功
     
    sysctl net.ipv4.ip_forward
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11

    在这里插入图片描述

    # 设置JVM后zai'f
    [root@vinjcent ~]# curl localhost:9200
    {
      "name" : "e1393351711e",
      "cluster_name" : "docker-cluster",
      "cluster_uuid" : "CxdcMtKmT3aIbH3vjEzL6Q",
      "version" : {
        "number" : "7.17.4",
        "build_flavor" : "default",
        "build_type" : "docker",
        "build_hash" : "79878662c54c886ae89206c685d9f1051a9d6411",
        "build_date" : "2022-05-18T18:04:20.964345128Z",
        "build_snapshot" : false,
        "lucene_version" : "8.11.1",
        "minimum_wire_compatibility_version" : "6.8.0",
        "minimum_index_compatibility_version" : "6.0.0-beta1"
      },
      "tagline" : "You Know, for Search"
    }
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    # 开启9200防火墙端口
    [root@vinjcent ~]# firewall-cmd --zone=public --add-port=9200/tcp --permanent
    # 重启防火墙
    [root@vinjcent ~]# systemctl restart firewalld.service
    # 查看开放端口
    [root@vinjcent ~]# firewall-cmd --list-ports
    # 关闭9200防火墙端口
    [root@vinjcent ~]# firewall-cmd --zone=public --remove-port=9200/tcp --permanent
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8

    2.4 可视化

    • portainer
    docker run -d -p 8088:9000 \
    --restart=always -v /var/run/docker.sock:/var/run/docker.sock --privileged=true portainer/portainer
    
    • 1
    • 2
    • Rancher(CI/CD再用)

    什么是 portainer

    Docker 图形化界面管理工具!提供一个后台面板

    在本机访问http://ip:8088/

    需要自己创建一个用户

    在这里插入图片描述

    选择本地

    在这里插入图片描述

    在这里插入图片描述

  • 相关阅读:
    第 45 届国际大学生程序设计竞赛(ICPC)亚洲区域赛(沈阳),签到题4题
    C# Onnx yolov8 竹签计数、一次性筷子计数
    SMALE实验室论文成果:多标签学习CSDN源码
    日本人之间交谈的一个方式了解下
    景联文科技:高质量的训练数据为高性能自动驾驶汽车提供动力
    Java集合面试题(总结最全面的面试题)
    leetcode 48. Rotate Image 旋转图像(Medium)
    《PyTorch深度学习实践》第十三讲RNN进阶
    C++前缀和算法的应用:摘水果 原理源码测试用例
    docker 灵活的构建 php 环境
  • 原文地址:https://blog.csdn.net/Wei_Naijia/article/details/125542855