Docker测试

nginx安装

  1. #1.搜索镜像 docker search nginx
  2. #2.下载镜像 docker pull nginx
  3. #3.运行测试
  4. #创建容器,启动容器,进入容器
  5. [root@localhost ~]# docker run -d --name nginx1 -p 3344:80 nginx
  6. f36f024f1d8e28f7836e67f43a225a0a788a62a3b857987e8215a9e7ddfe0120
  7. #查看已经创建容器
  8. [root@localhost ~]# docker ps
  9. CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
  10. f36f024f1d8e nginx "/docker-entrypoint.…" 17 seconds ago Up 16 seconds 0.0.0.0:3344->80/tcp, :::3344->80/tcp nginx1
  11. #测试容器
  12. [root@localhost ~]# curl localhost:3344
  13. <!DOCTYPE html>
  14. <html>
  15. <head>
  16. <title>Welcome to nginx!</title>
  17. <style>
  18. html { color-scheme: light dark; }
  19. body { width: 35em; margin: 0 auto;
  20. font-family: Tahoma, Verdana, Arial, sans-serif; }
  21. </style>
  22. </head>
  23. <body>
  24. <h1>Welcome to nginx!</h1>
  25. <p>If you see this page, the nginx web server is successfully installed and
  26. working. Further configuration is required.</p>
  27. <p>For online documentation and support please refer to
  28. <a href="http://nginx.org/">nginx.org</a>.<br/>
  29. Commercial support is available at
  30. <a href="http://nginx.com/">nginx.com</a>.</p>
  31. <p><em>Thank you for using nginx.</em></p>
  32. </body>
  33. </html>

tomcat 安装

  1. ## 下载镜像
  2. [root@localhost ~]# docker pull tomcat:9.0
  3. 9.0: Pulling from library/tomcat
  4. 6aefca2dc61d: Pull complete
  5. 967757d56527: Pull complete
  6. c357e2c68cb3: Pull complete
  7. c766e27afb21: Pull complete
  8. a747e81e6111: Pull complete
  9. 2859d18181fd: Pull complete
  10. 9706c6a496b8: Pull complete
  11. 1fcc3b6a96c1: Pull complete
  12. 0fa1c1ea9c77: Pull complete
  13. 3e7ac5f29e53: Pull complete
  14. Digest: sha256:0c7b2b413e72aa5cb23240379317c7aa244edff61fd07663d0fa5aec04839644
  15. Status: Downloaded newer image for tomcat:9.0
  16. docker.io/library/tomcat:9.0
  17. ## 查看镜像
  18. [root@localhost ~]# docker images
  19. REPOSITORY TAG IMAGE ID CREATED SIZE
  20. tomcat 9.0 6705ea17274a 8 days ago 680MB
  21. nginx latest fa5269854a5e 13 days ago 142MB
  22. hello-world latest feb5d9fea6a5 7 months ago 13.3kB
  23. ## 下载镜像
  24. [root@localhost ~]# docker pull tomcat
  25. Using default tag: latest
  26. latest: Pulling from library/tomcat
  27. 6aefca2dc61d: Already exists
  28. 967757d56527: Already exists
  29. c357e2c68cb3: Already exists
  30. c766e27afb21: Already exists
  31. a747e81e6111: Already exists
  32. 2859d18181fd: Already exists
  33. 9706c6a496b8: Already exists
  34. 1fcc3b6a96c1: Already exists
  35. 21609621b8c4: Pull complete
  36. d000f8b4b3ce: Pull complete
  37. Digest: sha256:3a407bd33b2e42f8e7ba8f736765cda37cea1cdf40a97262169f18e3edcb9acb
  38. Status: Downloaded newer image for tomcat:latest
  39. docker.io/library/tomcat:latest
  40. ##查看镜像
  41. [root@localhost ~]# docker images
  42. REPOSITORY TAG IMAGE ID CREATED SIZE
  43. tomcat 9.0 6705ea17274a 8 days ago 680MB
  44. tomcat latest 0183eb12bb0c 8 days ago 680MB
  45. nginx latest fa5269854a5e 13 days ago 142MB
  46. hello-world latest feb5d9fea6a5 7 months ago 13.3kB
  47. ##启动docker 进入容器
  48. [root@localhost ~]# docker run -d --name tomcat01 -p 3355:8080 tomcat:9.0
  49. 86181ae05bae1687109ddf144115966f3d88fcb64f911e1d8722c61557b8b92f
  50. [root@localhost ~]# docker ps
  51. CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
  52. 86181ae05bae tomcat:9.0 "catalina.sh run" 12 seconds ago Up 11 seconds 0.0.0.0:3355->8080/tcp, :::3355->8080/tcp tomcat01
  53. # 发现问题:
  54. #1.linux命令变少了.
  55. #2.没有webapp内容
  56. #原因:阿里云镜像的原因,默认是最小的镜像,所有不必要的都剔除掉

部署es+kibana

  1. #es 暴露端口很多
  2. #es 十分耗内存
  3. #es 的数据一般需要防止到安全目录,!挂载
  4. #--net somenetwork ? 网络配置
  5. #启动 elasticsearch
  6. docker run -d --name elasticsearch -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" elasticsearch:8.1.3
  7. #启动linux 就卡住了
  8. #docker stats 容器id 查看cpu的状态
  9. # es十分耗内存
  10. #增加内存限制 修改配置文件 -e环境配置修改
  11. docker run -d --name elasticsearch -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" -e ES_JAVA_OPTS="-Xms64m -Xmx512m" elasticsearch:8.1.3
  12. #测试es
  13. #启动下载
  14. [root@localhost ~]# docker run -d --name elasticsearch -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" -e ES_JAVA_OPTS="-Xms64m -Xmx512m" elasticsearch:7.6.2
  15. Unable to find image 'elasticsearch:7.6.2' locally
  16. 7.6.2: Pulling from library/elasticsearch
  17. ab5ef0e58194: Pull complete
  18. c4d1ca5c8a25: Pull complete
  19. 941a3cc8e7b8: Pull complete
  20. 43ec483d9618: Pull complete
  21. c486fd200684: Pull complete
  22. 1b960df074b2: Pull complete
  23. 1719d48d6823: Pull complete
  24. Digest: sha256:1b09dbd93085a1e7bca34830e77d2981521a7210e11f11eda997add1c12711fa
  25. Status: Downloaded newer image for elasticsearch:7.6.2
  26. 2ee09072591298053963519837645cd1dab59d666b98ccd50ca3de869d8ff489
  27. #查看正在运行容器
  28. [root@localhost ~]# docker ps
  29. CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
  30. 2ee090725912 elasticsearch:7.6.2 "/usr/local/bin/dock…" 10 seconds ago Up 9 seconds 0.0.0.0:9200->9200/tcp, :::9200->9200/tcp, 0.0.0.0:9300->9300/tcp, :::9300->9300/tcp elasticsearch
  31. #测试,是否启动成功
  32. [root@localhost ~]# curl localhost:9200
  33. {
  34. "name" : "2ee090725912",
  35. "cluster_name" : "docker-cluster",
  36. "cluster_uuid" : "7Jh05HcdTL2mlc6NCPinDw",
  37. "version" : {
  38. "number" : "7.6.2",
  39. "build_flavor" : "default",
  40. "build_type" : "docker",
  41. "build_hash" : "ef48eb35cf30adf4db14086e8aabd07ef6fb113f",
  42. "build_date" : "2020-03-26T06:34:37.794943Z",
  43. "build_snapshot" : false,
  44. "lucene_version" : "8.4.0",
  45. "minimum_wire_compatibility_version" : "6.8.0",
  46. "minimum_index_compatibility_version" : "6.0.0-beta1"
  47. },
  48. "tagline" : "You Know, for Search"
  49. }

可视化

  • portainer
  1. docker run -d -p 8088:9000 \
  2. --restart=always -v /var/run/docker.sock:/var/run/docker.sock --privileged=true portainer/portainer

Docker部署测试 - 图1

  • Rancher