• Docker配置Nginx、tomcat、elasticsearch


    配置nginx

    需要先pull下来

    #启动nginx
    -d 表示后台运行
    -p 表示暴露端口,将80暴露为3344
    [root@iZf8zhsqf64x47n1tpdy6oZ home]# docker run -d -p:3344:80 nginx
    5dd62cea7681975d37d1a9867bc9776de0206519f624b461346ac83025656642
    [root@iZf8zhsqf64x47n1tpdy6oZ home]# docker ps
    CONTAINER ID        IMAGE                 COMMAND                  CREATED             STATUS              PORTS                                        NAMES
    5dd62cea7681        nginx                 "/docker-entrypoin..."   5 seconds ago       Up 4 seconds        0.0.0.0:3344->80/tcp                         inspiring_bell
    af3bc99f4a47        portainer/portainer   "/portainer"             2 days ago          Up 27 hours         8000/tcp, 9443/tcp, 0.0.0.0:9000->9000/tcp   portainer
    
    #本机自测
    [root@iZf8zhsqf64x47n1tpdy6oZ home]# 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

    在这里插入图片描述

    查看nginx的配置文件

    [root@iZf8zhsqf64x47n1tpdy6oZ home]# docker ps
    CONTAINER ID        IMAGE                 COMMAND                  CREATED             STATUS              PORTS                                        NAMES
    5dd62cea7681        nginx                 "/docker-entrypoin..."   19 minutes ago      Up 19 minutes       0.0.0.0:3344->80/tcp                         inspiring_bell
    af3bc99f4a47        portainer/portainer   "/portainer"             2 days ago          Up 27 hours         8000/tcp, 9443/tcp, 0.0.0.0:9000->9000/tcp   portainer
    
    #进入容器内部
    [root@iZf8zhsqf64x47n1tpdy6oZ home]# docker exec -it 5dd62cea7681 /bin/bash
    root@5dd62cea7681:/# whereis nginx
    nginx: /usr/sbin/nginx /usr/lib/nginx /etc/nginx /usr/share/nginx
    root@5dd62cea7681:/# cd /etc/nginx
    root@5dd62cea7681:/etc/nginx# ls
    conf.d	fastcgi_params	mime.types  modules  nginx.conf  scgi_params  uwsgi_params
    root@5dd62cea7681:/etc/nginx#
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13

    配置tomcat

    #当直接运行时不存在就会去下载
    docker run -it --rm tomcat:9.0
    --rm表示运行完成后就会自己删除,我们之前的都是不会自动删除的
    
    • 1
    • 2
    • 3

    遇到的问题:当我们运行了tomcat之后,是无法访问tomcat的首页的,这是因为镜像使得tomcat变成精简版本,只要能运行的版本就行,所以,如果想访问的话,就需要进行相关操作

    #进入tomcat
    [root@iZf8zhsqf64x47n1tpdy6oZ home]# docker exec -it 9f62708dfca5 /bin/bash
    root@9f62708dfca5:/usr/local/tomcat# ls
    BUILDING.txt	 LICENSE  README.md	 RUNNING.txt  conf  logs	    temp     webapps.dist
    CONTRIBUTING.md  NOTICE   RELEASE-NOTES  bin	      lib   native-jni-lib  webapps  work
    root@9f62708dfca5:/usr/local/tomcat# cd webapps
    #发现webapps里面为空
    root@9f62708dfca5:/usr/local/tomcat/webapps# ls
    root@9f62708dfca5:/usr/local/tomcat/webapps# cd ..
    #复制webapps.dist文件内容到webapps中去
    root@9f62708dfca5:/usr/local/tomcat# cp -r webapps.dist/* webapps
    root@9f62708dfca5:/usr/local/tomcat# cd webapps
    root@9f62708dfca5:/usr/local/tomcat/webapps# ls
    ROOT  docs  examples  host-manager  manager
    root@9f62708dfca5:/usr/local/tomcat/webapps# 
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16

    问题解决!!

    配置elasticsearch

    elasticsearch是什么耗内存的,因此需要修改配置,限制内存

    #限制最大内存为512m,最小内存为64m
    [root@iZf8zhsqf64x47n1tpdy6oZ home]# docker run -d -p 9200:9200 -e 9300:9300 -e "discovery.type=single-node" -e ES_JAVA_OPTS="-Xms64m -Xmx512m" elasticsearch:7.6.2
    
    
    • 1
    • 2
    • 3

    可视化

    docker run -d -p 8088:9000 \
    --restart=always -v /var/run/docker.sock:/var/run/docker.sock --privileged=true portainer/portainer
    
    • 1
    • 2
  • 相关阅读:
    法国心理健康平台【Teale】完成1000万欧元A轮融资
    安装Android SDK点击SDK Manager.exe一闪而退完美解决方案
    提高生产力和降低成本:CISO的网络安全绩效指标
    消息队列基本原理和选型对比
    20230922 比赛总结
    探索物理学的奥秘:解锁自然世界的钥匙
    【微信小程序入门到精通】— swiper 超详细的属性值讲解!确定不来看看?
    java ThreadPoolExecutor怎么设置队列不满也能达到最大线程池大小
    北理工嵩天Python语言程序设计笔记(2 Python基本语法元素)
    vue学习
  • 原文地址:https://blog.csdn.net/qq_64420904/article/details/136754278