【Docker学习笔记 三】Docker常用容器安装及图形化管理工具
经过之前的命令学习,今天这篇Blog主要是拿几个容器练手来熟悉之前的docker命令、进行一些简单的请求测试,并且通过工具面板可视化的去管理容器。到此为止,学习到的Docker容器的应用概念还是停留在单个组件的功能实现上,大型的分布式服务集群其实是融合了多种中间件去实现的,这到底是如何实现的,容器如何联合起来提供服务,还是比较好奇?所以还是比较期待后续容器编排一些高级概念的学习。
上一篇Blog详细介绍了如何在CentOS上进行Docker的安装、卸载以及如何进行镜像加速,了解了Docker大致的运行流程以及常用的命令。时隔半个月之后,度过了过节失落期后再次拾起来自己的年度计划继续进行这方面知识的学习。在了解了常用命令后,就要开始对常用容器下手训练了,比如一些常用的中间件以及服务器。
常用容器部署
通过上一篇Blog命令的学习,来运行一下以下几个常用的中间件和服务器的容器。
Nginx部署
Nginx常用做负载均衡和反向代理,我们通过Docker来使用容器化的Nginx,从容器站点搜索:https://hub.docker.com/:
1 搜索并下载镜像
搜索到nginx镜像后进行下载
Last login: Fri Feb 4 00:32:05 2022 from 192.168.5.1
[root@192 ~]# docker search nginx
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
bitnami/nginx Bitnami nginx Docker Image 117 [OK]
bitnami/wordpress-nginx Bitnami Docker Image for WordPress with NGINX 55 [OK]
ubuntu/nginx Nginx, a high-performance reverse proxy & we… 31
bitnami/nginx-ingress-controller Bitnami Docker Image for NGINX Ingress Contr… 15 [OK]
rancher/nginx-ingress-controller 9
ibmcom/nginx-ingress-controller Docker Image for IBM Cloud Private-CE (Commu… 4
bitnami/nginx-ldap-auth-daemon 3
rancher/nginx-ingress-controller-defaultbackend 2
circleci/nginx This image is for internal use 2
bitnami/nginx-exporter 1
rancher/nginx 1
rancher/nginx-ingress-controller-amd64 0
kasmweb/nginx An Nginx image based off nginx:alpine and in… 0
rancher/nginx-conf 0
rancher/nginx-ssl 0
ibmcom/nginx-ppc64le Docker image for nginx-ppc64le 0
wallarm/nginx-ingress-controller Kubernetes Ingress Controller with Wallarm e… 0
ibmcom/nginx-ingress-controller-ppc64le Docker Image for IBM Cloud Private-CE (Commu… 0
rancher/nginx-proxy 0
bitnami/nginx-intel 0
wallarm/nginx-ingress-controller-amd64 Kubernetes Ingress Controller with Wallarm e… 0
ibmcom/nginx-ingress-controller-amd64 0
ibmcom/nginx-ingress-controller-s390x 0
wallarm/nginx-amd64 0
nginx Official build of Nginx. 0 [OK]
[root@192 ~]# docker pull nginx
Using default tag: latest
latest: Pulling from library/nginx
a2abf6c4d29d: Pull complete
a9edb18cadd1: Pull complete
589b7251471a: Pull complete
186b1aaa4aa6: Pull complete
b4df32aa5a72: Pull complete
a0bcbecc962e: Pull complete
Digest: sha256:0d17b565c37bcbd895e9d92315a05c1c3c9a29f762b011a10c54a66cd53c9b31
Status: Downloaded newer image for nginx:latest
docker.io/library/nginx:latest
[root@192 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest 605c77e624dd 7 weeks ago 141MB
tomcat latest fb5657adc892 8 weeks ago 680MB
mysql latest 3218b38490ce 2 months ago 516MB
hello-world latest feb5d9fea6a5 4 months ago 13.3kB
centos latest 5d0da3dc9764 5 months ago 231MB
[root@192 ~]#
2 运行测试
通过后台模式运行nginx容器
docker run -d --name nginx-tml -p 3334:80 nginx
-d 后台运行
--name 给容器命名
-p 3334:80 将宿主机的端口3334映射到该容器的80端口
如果在run的时候报了如下异常:
WARNING: IPv4 forwarding is disabled. Networking will not work.
则说明ip转发没有打开,需要通过如下方式打开:
vim /etc/sysctl.conf
#配置转发
net.ipv4.ip_forward=1
#重启服务,让配置生效
systemctl restart network
#查看是否成功,如果返回为“net.ipv4.ip_forward = 1”则表示成功
sysctl net.ipv4.ip_forward
运行命令如下:
[root@192 ~]# docker run -d --name nginx-tml -p 3334:80 nginx
b8ae778bad8c7b53df465ee033f14b909ac0096306d38a39ea5c211910613aa0
[root@192 ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
b8ae778bad8c nginx "/docker-entrypoint.…" 2 minutes ago Up 2 minutes 0.0.0.0:3334->80/tcp, :::3334->80/tcp nginx-tml
4ed9be7f96c8 centos "/bin/bash" 2 weeks ago Up 2 weeks inspiring_rhodes
cc886973b2cb centos "/bin/sh -c 'while t…" 2 weeks ago Up 2 weeks suspicious_borg
1c1dd47ce82c centos "/bin/bash" 2 weeks ago Up 2 weeks elated_colden
945abcb48a14 tomcat "catalina.sh run" 2 weeks ago Up 2 weeks 8080/tcp quizzical_golick
0558e745b9b0 tomcat "catalina.sh run" 2 weeks ago Up 2 weeks 8080/tcp heuristic_chebyshev
宿主机与容器的端口暴露映射
3 访问测试
通过公网网络端口访问nginx
[root@192 ~]# curl localhost:3334
<!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>
通过公网也是可以访问到的:
Tomcat部署
Tomcat是我们常用的服务器,同样可以从dockerhub搜索到:
1 搜索并下载镜像
之前虽然下载过tomcat镜像和容器,这里就复习下之前的命令,删除容器和镜像重新下载吧:
[root@192 ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
b8ae778bad8c nginx "/docker-entrypoint.…" 31 minutes ago Up 31 minutes 0.0.0.0:3334->80/tcp, :::3334->80/tcp nginx-tml
4ed9be7f96c8 centos "/bin/bash" 2 weeks ago Up 2 weeks inspiring_rhodes
cc886973b2cb centos "/bin/sh -c 'while t…" 2 weeks ago Up 2 weeks suspicious_borg
1c1dd47ce82c centos "/bin/bash" 2 weeks ago Up 2 weeks elated_colden
945abcb48a14 tomcat "catalina.sh run" 2 weeks ago Up 2 weeks 8080/tcp quizzical_golick
0558e745b9b0 tomcat "catalina.sh run" 2 weeks ago Up 2 weeks 8080/tcp heuristic_chebyshev
[root@192 ~]# docker rm -f 945abcb48a14
945abcb48a14
[root@192 ~]# docker rm -f 0558e745b9b0
0558e745b9b0
[root@192 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest 605c77e624dd 7 weeks ago 141MB
tomcat latest fb5657adc892 8 weeks ago 680MB
mysql latest 3218b38490ce 2 months ago 516MB
hello-world latest feb5d9fea6a5 4 months ago 13.3kB
centos latest 5d0da3dc9764 5 months ago 231MB
[root@192 ~]# docker rmi -f fb5657adc892
Untagged: tomcat:latest
Untagged: tomcat@sha256:9dee185c3b161cdfede1f5e35e8b56ebc9de88ed3a79526939701f3537a52324
Deleted: sha256:fb5657adc892ed15910445588404c798b57f741e9921ff3c1f1abe01dbb56906
[root@192 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest 605c77e624dd 7 weeks ago 141MB
mysql latest 3218b38490ce 2 months ago 516MB
hello-world latest feb5d9fea6a5 4 months ago 13.3kB
centos latest 5d0da3dc9764 5 months ago 231MB
然后再通过命令重新搜索下载tomcat镜像
[root@192 ~]# docker search tomcat
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
bitnami/tomcat Bitnami Tomcat Docker Image 44 [OK]
aallam/tomcat-mysql Debian, Oracle JDK, Tomcat & MySQL 12 [OK]
arm64v8/tomcat Apache Tomcat is an open source implementati… 7
rightctrl/tomcat CentOS , Oracle Java, tomcat application ssl… 7 [OK]
tomcat2111/pisignage-server PiSignage Server 3 [OK]
jelastic/tomcat An image of the Tomcat Java application serv… 3
amd64/tomcat Apache Tomcat is an open source implementati… 3
cfje/tomcat-resource Tomcat Concourse Resource 2
chenyufeng/tomcat-centos tomcat基于centos6的镜像 1 [OK]
ppc64le/tomcat Apache Tomcat is an open source implementati… 1
tomcatling/jupyterhub_aws 1
softwareplant/tomcat Tomcat images for jira-cloud testing 0 [OK]
store/microsoft/defaultpublisher Zulu for Azure build of OpenJDK 0
tomcat2111/phpredisadmin This is a Docker image for phpredisadmin 0 [OK]
tomcat2111/bitbucket-pipelines-elasticsearch Elasticsearch for Bitbucket's Pipelines 0
tomcat2111/papercut-mf PaperCut MF Application Server 0
tomcat0823/auto1 0
tomcatengineering/pg_backup_rotated Clone of martianrock/pg_backup_rotated but w… 0
s390x/tomcat Apache Tomcat is an open source implementati… 0
tomcatengineering/docker_swarm_exporter Prometheus metrics exporter for Docker Swarms 0
secoresearch/tomcat-varnish Tomcat and Varnish 5.0 0 [OK]
tomcat2111/piwik Matomo (formerly Piwik) image 0
tomee Apache TomEE is an all-Apache Java EE certif… 0 [OK]
tomcat2111/redaxo Redaxo 0
tomcat Apache Tomcat is an open source implementati… 0 [OK]
[root@192 ~]# docker pull tomcat
Using default tag: latest
latest: Pulling from library/tomcat
0e29546d541c: Already exists
9b829c73b52b: Already exists
cb5b7ae36172: Already exists
6494e4811622: Already exists
668f6fcc5fa5: Already exists
dc120c3e0290: Already exists
8f7c0eebb7b1: Already exists
77b694f83996: Already exists
0f611256ec3a: Already exists
4f25def12f23: Already exists
Digest: sha256:9dee185c3b161cdfede1f5e35e8b56ebc9de88ed3a79526939701f3537a52324
Status: Downloaded newer image for tomcat:latest
docker.io/library/tomcat:latest
[root@192 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest 605c77e624dd 7 weeks ago 141MB
tomcat latest fb5657adc892 8 weeks ago 680MB
mysql latest 3218b38490ce 2 months ago 516MB
hello-world latest feb5d9fea6a5 4 months ago 13.3kB
centos latest 5d0da3dc9764 5 months ago 231MB
2 运行测试
然后以后台的方式启动下tomcat:
[root@192 ~]# docker run -d --name tomcat-tml -p 3335:8080 tomcat
2f59536a92da2d8212bb767da507b3b76102bc47df241c6046c866f0ccfeac7c
[root@192 ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
2f59536a92da tomcat "catalina.sh run" 8 seconds ago Up 6 seconds 0.0.0.0:3335->8080/tcp, :::3335->8080/tcp tomcat-tml
b8ae778bad8c nginx "/docker-entrypoint.…" 38 minutes ago Up 38 minutes 0.0.0.0:3334->80/tcp, :::3334->80/tcp nginx-tml
4ed9be7f96c8 centos "/bin/bash" 2 weeks ago Up 2 weeks inspiring_rhodes
cc886973b2cb centos "/bin/sh -c 'while t…" 2 weeks ago Up 2 weeks suspicious_borg
1c1dd47ce82c centos "/bin/bash" 2 weeks ago Up 2 weeks elated_colden
[root@192 ~]# curl localhost:3335
<!doctype html><html lang="en"><head><title>HTTP Status 404 – Not Found</title><style type="text/css">body {font-family:Tahoma,Arial,sans-serif;} h1, h2, h3, b {color:white;background-color:#525D76;} h1 {font-size:22px;} h2 {font-size:16px;} h3 {font-size:14px;} p {font-size:12px;} a {color:black;} .line {height:1px;background-color:#525D76;border:none;}</style></head><body><h1>HTTP Status 404 – Not Found</h1><hr class="line" /><p><b>Type</b> Status Report</p><p><b>Description</b> The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.</p><hr class="line" /><h3>Apache Tomcat/10.0.14</h3></body></html>[root@192 ~]#
这里看到是404,这是因为:阿里云镜像默认下载的是最小的镜像,保证最小的运行环境,容器中的命令是少了
oot@192 ~]# docker exec -it tomcat-tml /bin/bash
root@2f59536a92da:/usr/local/tomcat# ls
BUILDING.txt CONTRIBUTING.md LICENSE NOTICE README.md RELEASE-NOTES RUNNING.txt bin conf lib logs native-jni-lib temp webapps webapps.dist work
root@2f59536a92da:/usr/local/tomcat# cd webapps.dist
root@2f59536a92da:/usr/local/tomcat/webapps.dist# ls
ROOT docs examples host-manager manager
root@2f59536a92da:/usr/local/tomcat/webapps.dist# cd ROOT
root@2f59536a92da:/usr/local/tomcat/webapps.dist/ROOT# ls
RELEASE-NOTES.txt WEB-INF asf-logo-wide.svg bg-button.png bg-middle.png bg-nav.png bg-upper.png favicon.ico index.jsp tomcat.css tomcat.svg
root@2f59536a92da:/usr/local/tomcat/webapps.dist/ROOT# ls
RELEASE-NOTES.txt WEB-INF asf-logo-wide.svg bg-button.png bg-middle.png bg-nav.png bg-upper.png favicon.ico index.jsp tomcat.css tomcat.svg
root@2f59536a92da:/usr/local/tomcat/webapps.dist/ROOT# cd ../../
root@2f59536a92da:/usr/local/tomcat# cd webapps
root@2f59536a92da:/usr/local/tomcat/webapps# ls
root@2f59536a92da:/usr/local/tomcat/webapps# cp -r /usr/local/tomcat/webapps.dist/* /usr/local/tomcat/webapps/
root@2f59536a92da:/usr/local/tomcat/webapps# ls
ROOT docs examples host-manager manager
root@2f59536a92da:/usr/local/tomcat/webapps# exit
exit
3 访问测试
再次访问测试查看:
[root@192 ~]# curl localhost:3335
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Apache Tomcat/10.0.14</title>
<link href="favicon.ico" rel="icon" type="image/x-icon" />
<link href="tomcat.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="wrapper">
<div id="navigation" class="curved container">
<span id="nav-home"><a href="https://tomcat.apache.org/">Home</a></span>
<span id="nav-hosts"><a href="/docs/">Documentation</a></span>
<span id="nav-config"><a href="/docs/config/">Configuration</a></span>
<span id="nav-examples"><a href="/examples/">Examples</a></span>
<span id="nav-wiki"><a href="https://wiki.apache.org/tomcat/FrontPage">Wiki</a></span>
<span id="nav-lists"><a href="https://tomcat.apache.org/lists.html">Mailing Lists</a></span>
<span id="nav-help"><a href="https://tomcat.apache.org/findhelp.html">Find Help</a></span>
<br class="separator" />
</div>
<div id="asf-box">
<h1>Apache Tomcat/10.0.14</h1>
</div>
<div id="upper" class="curved container">
<div id="congrats" class="curved container">
<h2>If you're seeing this, you've successfully installed Tomcat. Congratulations!</h2>
</div>
<div id="notice">
<img id="tomcat-logo" src="tomcat.svg" alt="[tomcat logo]" />
<div id="tasks">
<h3>Recommended Reading:</h3>
<h4><a href="/docs/security-howto.html">Security Considerations How-To</a></h4>
<h4><a href="/docs/manager-howto.html">Manager Application How-To</a></h4>
<h4><a href="/docs/cluster-howto.html">Clustering/Session Replication How-To</a></h4>
</div>
</div>
<div id="actions">
<div class="button">
<a class="container shadow" href="/manager/status"><span>Server Status</span></a>
</div>
<div class="button">
<a class="container shadow" href="/manager/html"><span>Manager App</span></a>
</div>
<div class="button">
<a class="container shadow" href="/host-manager/html"><span>Host Manager</span></a>
</div>
</div>
<br class="separator" />
</div>
<div id="middle" class="curved container">
<h3>Developer Quick Start</h3>
<div class="col25">
<div class="container">
<p><a href="/docs/setup.html">Tomcat Setup</a></p>
<p><a href="/docs/appdev/">First Web Application</a></p>
</div>
</div>
<div class="col25">
<div class="container">
<p><a href="/docs/realm-howto.html">Realms & AAA</a></p>
<p><a href="/docs/jndi-datasource-examples-howto.html">JDBC DataSources</a></p>
</div>
</div>
<div class="col25">
<div class="container">
<p><a href="/examples/">Examples</a></p>
</div>
</div>
<div class="col25">
<div class="container">
<p><a href="https://wiki.apache.org/tomcat/Specifications">Servlet Specifications</a></p>
<p><a href="https://wiki.apache.org/tomcat/TomcatVersions">Tomcat Versions</a></p>
</div>
</div>
<br class="separator" />
</div>
<div id="lower">
<div id="low-manage" class="">
<div class="curved container">
<h3>Managing Tomcat</h3>
<p>For security, access to the <a href="/manager/html">manager webapp</a> is restricted.
Users are defined in:</p>
<pre>$CATALINA_HOME/conf/tomcat-users.xml</pre>
<p>In Tomcat 10.0 access to the manager application is split between
different users. <a href="/docs/manager-howto.html">Read more...</a></p>
<br />
<h4><a href="/docs/RELEASE-NOTES.txt">Release Notes</a></h4>
<h4><a href="/docs/changelog.html">Changelog</a></h4>
<h4><a href="https://tomcat.apache.org/migration.html">Migration Guide</a></h4>
<h4><a href="https://tomcat.apache.org/security.html">Security Notices</a></h4>
</div>
</div>
<div id="low-docs" class="">
<div class="curved container">
<h3>Documentation</h3>
<h4><a href="/docs/">Tomcat 10.0 Documentation</a></h4>
<h4><a href="/docs/config/">Tomcat 10.0 Configuration</a></h4>
<h4><a href="https://wiki.apache.org/tomcat/FrontPage">Tomcat Wiki</a></h4>
<p>Find additional important configuration information in:</p>
<pre>$CATALINA_HOME/RUNNING.txt</pre>
<p>Developers may be interested in:</p>
<ul>
<li><a href="https://tomcat.apache.org/bugreport.html">Tomcat 10.0 Bug Database</a></li>
<li><a href="/docs/api/index.html">Tomcat 10.0 JavaDocs</a></li>
<li><a href="https://github.com/apache/tomcat/tree/10.0.x">Tomcat 10.0 Git Repository at GitHub</a></li>
</ul>
</div>
</div>
<div id="low-help" class="">
<div class="curved container">
<h3>Getting Help</h3>
<h4><a href="https://tomcat.apache.org/faq/">FAQ</a> and <a href="https://tomcat.apache.org/lists.html">Mailing Lists</a></h4>
<p>The following mailing lists are available:</p>
<ul>
<li id="list-announce"><strong><a href="https://tomcat.apache.org/lists.html#tomcat-announce">tomcat-announce</a><br />
Important announcements, releases, security vulnerability notifications. (Low volume).</strong>
</li>
<li><a href="https://tomcat.apache.org/lists.html#tomcat-users">tomcat-users</a><br />
User support and discussion
</li>
<li><a href="https://tomcat.apache.org/lists.html#taglibs-user">taglibs-user</a><br />
User support and discussion for <a href="https://tomcat.apache.org/taglibs/">Apache Taglibs</a>
</li>
<li><a href="https://tomcat.apache.org/lists.html#tomcat-dev">tomcat-dev</a><br />
Development mailing list, including commit messages
</li>
</ul>
</div>
</div>
<br class="separator" />
</div>
<div id="footer" class="curved container">
<div class="col20">
<div class="container">
<h4>Other Downloads</h4>
<ul>
<li><a href="https://tomcat.apache.org/download-connectors.cgi">Tomcat Connectors</a></li>
<li><a href="https://tomcat.apache.org/download-native.cgi">Tomcat Native</a></li>
<li><a href="https://tomcat.apache.org/taglibs/">Taglibs</a></li>
<li><a href="/docs/deployer-howto.html">Deployer</a></li>
</ul>
</div>
</div>
<div class="col20">
<div class="container">
<h4>Other Documentation</h4>
<ul>
<li><a href="https://tomcat.apache.org/connectors-doc/">Tomcat Connectors</a></li>
<li><a href="https://tomcat.apache.org/connectors-doc/">mod_jk Documentation</a></li>
<li><a href="https://tomcat.apache.org/native-doc/">Tomcat Native</a></li>
<li><a href="/docs/deployer-howto.html">Deployer</a></li>
</ul>
</div>
</div>
<div class="col20">
<div class="container">
<h4>Get Involved</h4>
<ul>
<li><a href="https://tomcat.apache.org/getinvolved.html">Overview</a></li>
<li><a href="https://tomcat.apache.org/source.html">Source Repositories</a></li>
<li><a href="https://tomcat.apache.org/lists.html">Mailing Lists</a></li>
<li><a href="https://wiki.apache.org/tomcat/FrontPage">Wiki</a></li>
</ul>
</div>
</div>
<div class="col20">
<div class="container">
<h4>Miscellaneous</h4>
<ul>
<li><a href="https://tomcat.apache.org/contact.html">Contact</a></li>
<li><a href="https://tomcat.apache.org/legal.html">Legal</a></li>
<li><a href="https://www.apache.org/foundation/sponsorship.html">Sponsorship</a></li>
<li><a href="https://www.apache.org/foundation/thanks.html">Thanks</a></li>
</ul>
</div>
</div>
<div class="col20">
<div class="container">
<h4>Apache Software Foundation</h4>
<ul>
<li><a href="https://tomcat.apache.org/whoweare.html">Who We Are</a></li>
<li><a href="https://tomcat.apache.org/heritage.html">Heritage</a></li>
<li><a href="https://www.apache.org">Apache Home</a></li>
<li><a href="https://tomcat.apache.org/resources.html">Resources</a></li>
</ul>
</div>
</div>
<br class="separator" />
</div>
<p class="copyright">Copyright ©1999-2022 Apache Software Foundation. All Rights Reserved</p>
</div>
</body>
</html>
[root@192 ~]#
公网访问
ElasticSearch部署
ElasticSearch是我们常用的搜索引擎,es暴露端口较多且占用内存较高
1 搜索并下载镜像
先搜索并下载elasticsearch的镜像
[root@192 ~]# docker search elasticsearch
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
elastichq/elasticsearch-hq Official Docker image for ElasticHQ: Elastic… 78 [OK]
bitnami/elasticsearch Bitnami Docker Image for Elasticsearch 47 [OK]
justwatch/elasticsearch_exporter Elasticsearch stats exporter for Prometheus 17
bitnami/elasticsearch-exporter Bitnami Elasticsearch Exporter Docker Image 4 [OK]
barchart/elasticsearch-aws Elasticsearch AWS node 3
rancher/elasticsearch-conf 3
bitnami/elasticsearch-curator 2
ibmcom/elasticsearch Docker Image for IBM Cloud private-CE (Commu… 1
ibmcom/elasticsearch-ppc64le Docker Image for IBM Cloud Private-CE (Commu… 1
rancher/elasticsearch-bootstrap 1
ibmcom/elasticsearch-s390x 1
atlassian/dynamodb-elasticsearch-indexer An indexer for indexing DynamoDB tables in E… 1
ibmcom/elasticsearch-amd64 0
ibmcom/elasticsearch-exporter-amd64 0
ibmcom/elasticsearch-plugin-searchguard-amd64 0
ibmcom/elasticsearch-exporter-ppc64le 0
ibmcom/elasticsearch-plugin-searchguard-s390x 0
ibmcom/elasticsearch-exporter-s390x 0
ibmcom/elasticsearch-plugin-searchguard-ppc64le 0
ibmcom/elasticsearch-dump 0
rancher/elasticsearch 0
amazon/opendistro-for-elasticsearch-data-prepper The Docker image for the Open Distribution f… 0
ibmcom/elasticsearch-exporter 0
ibmcom/elasticsearch-plugin-searchguard 0
kibana Kibana gives shape to any kind of data — str… 0 [OK]
[root@192 ~]# docker pull elasticsearch
Using default tag: latest
latest: Pulling from library/elasticsearch
05d1a5232b46: Pull complete
5cee356eda6b: Pull complete
89d3385f0fd3: Pull complete
65dd87f6620b: Pull complete
78a183a01190: Pull complete
1a4499c85f97: Pull complete
2c9d39b4bfc1: Pull complete
1b1cec2222c9: Pull complete
59ff4ce9df68: Pull complete
1976bc3ee432: Pull complete
5af49e8af381: Pull complete
42c8b75ff7af: Pull complete
7e6902915254: Pull complete
99853874fa54: Pull complete
596fbad6fcff: Pull complete
Digest: sha256:a8081d995ef3443dc6d077093172a5931e02cdb8ffddbf05c67e01d348a9770e
Status: Downloaded newer image for elasticsearch:latest
docker.io/library/elasticsearch:latest
[root@192 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest 605c77e624dd 7 weeks ago 141MB
tomcat latest fb5657adc892 8 weeks ago 680MB
mysql latest 3218b38490ce 2 months ago 516MB
hello-world latest feb5d9fea6a5 4 months ago 13.3kB
centos latest 5d0da3dc9764 5 months ago 231MB
elasticsearch latest 5acf0e8da90b 3 years ago 486MB
[root@192 ~]#
添加 -e ES_JAVA_OPTS="-Xms128m -Xmx512m"
配置ElasticSearch的虚拟机占用的内存大小
2 运行测试
给es设定最大内存进行启动
[root@192 ~]# docker run -d --name elasticsearch-tml -p 3392:9200 -p 3393:9300 -e "discovery.type=single-node" -e ES_JAVA_OPTS="-Xms128m -Xmx512m" elasticsearch
bd6877cd46cebf68c2f9b0571dafde1da474c159b28939d9a24faabe21a86802
[root@192 ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
bd6877cd46ce elasticsearch "/docker-entrypoint.…" 13 seconds ago Up 12 seconds 0.0.0.0:3392->9200/tcp, :::3392->9200/tcp, 0.0.0.0:3393->9300/tcp, :::3393->9300/tcp elasticsearch-tml
2f59536a92da tomcat "catalina.sh run" 2 hours ago Up 2 hours 0.0.0.0:3335->8080/tcp, :::3335->8080/tcp tomcat-tml
b8ae778bad8c nginx "/docker-entrypoint.…" 2 hours ago Up 2 hours 0.0.0.0:3334->80/tcp, :::3334->80/tcp nginx-tml
4ed9be7f96c8 centos "/bin/bash" 2 weeks ago Up 2 weeks inspiring_rhodes
cc886973b2cb centos "/bin/sh -c 'while t…" 2 weeks ago Up 2 weeks
通过命令stats查看内存使用情况:
[root@192 ~]# docker stats bd6877cd46ce
CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS
bd6877cd46ce elasticsearch-tml 0.02% 184.2MiB / 972.4MiB 18.94% 656B / 0B 941MB / 537kB 31
CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS
bd6877cd46ce elasticsearch-tml 0.02% 184.2MiB / 972.4MiB 18.94% 656B / 0B 941MB / 537kB 31
CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS
bd6877cd46ce elasticsearch-tml 0.80% 184.7MiB / 972.4MiB 18.99% 656B / 0B 948MB / 537kB 31
CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS
bd6877cd46ce elasticsearch-tml 0.80% 184.7MiB / 972.4MiB 18.99% 656B / 0B 948MB / 537kB 31
CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS
3 访问测试
我们进行访问测试看下效果:
[root@192 ~]# curl localhost:3392
{
"name" : "xcQQz-u",
"cluster_name" : "elasticsearch",
"cluster_uuid" : "D5CjYDPoQvOzarlg-GY0nQ",
"version" : {
"number" : "5.6.12",
"build_hash" : "cfe3d9f",
"build_date" : "2018-09-10T20:12:43.732Z",
"build_snapshot" : false,
"lucene_version" : "6.6.1"
},
"tagline" : "You Know, for Search"
}
[root@192 ~]#
公网访问效果如下:
当然也可以部署新版本es并访问,很简单:
[root@192 ~]# docker run -d --name elasticsearch-tml-7.6.2 -p 3396:9200 -p 3397:9300 -e "discovery.type=single-node" -e ES_JAVA_OPTS="-Xms128m -Xmx512m" elasticsearch:7.6.2
Unable to find image 'elasticsearch:7.6.2' locally
7.6.2: Pulling from library/elasticsearch
ab5ef0e58194: Pull complete
c4d1ca5c8a25: Pull complete
941a3cc8e7b8: Pull complete
43ec483d9618: Pull complete
c486fd200684: Pull complete
1b960df074b2: Pull complete
1719d48d6823: Pull complete
Digest: sha256:1b09dbd93085a1e7bca34830e77d2981521a7210e11f11eda997add1c12711fa
Status: Downloaded newer image for elasticsearch:7.6.2
3b66fa35905f90af7d8ddfb37b457f31d9045a9ffebc2f1c9e99c7d0374bae01
[root@192 ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
3b66fa35905f elasticsearch:7.6.2 "/usr/local/bin/dock…" 14 seconds ago Up 8 seconds 0.0.0.0:3396->9200/tcp, :::3396->9200/tcp, 0.0.0.0:3397->9300/tcp, :::3397->9300/tcp elasticsearch-tml-7.6.2
bd6877cd46ce elasticsearch "/docker-entrypoint.…" 7 minutes ago Up 7 minutes 0.0.0.0:3392->9200/tcp, :::3392->9200/tcp, 0.0.0.0:3393->9300/tcp, :::3393->9300/tcp elasticsearch-tml
2f59536a92da tomcat "catalina.sh run" 2 hours ago Up 2 hours 0.0.0.0:3335->8080/tcp, :::3335->8080/tcp tomcat-tml
b8ae778bad8c nginx "/docker-entrypoint.…" 2 hours ago Up 2 hours 0.0.0.0:3334->80/tcp, :::3334->80/tcp nginx-tml
4ed9be7f96c8 centos "/bin/bash" 2 weeks ago Up 2 weeks inspiring_rhodes
cc886973b2cb centos "/bin/sh -c 'while t…" 2 weeks ago Up 2 weeks suspicious_borg
[root@192 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest 605c77e624dd 7 weeks ago 141MB
tomcat latest fb5657adc892 8 weeks ago 680MB
mysql latest 3218b38490ce 2 months ago 516MB
hello-world latest feb5d9fea6a5 4 months ago 13.3kB
centos latest 5d0da3dc9764 5 months ago 231MB
elasticsearch 7.6.2 f29a1ee41030 23 months ago 791MB
elasticsearch latest 5acf0e8da90b 3 years ago 486MB
公网访问如下:
MySQL部署
MySQL是我们的常用的数据库管理软件:
1 搜索并下载镜像
同样的搜索和下载镜像:
[root@192 ~]# docker search mysql
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
mysql/mysql-server Optimized MySQL Server Docker images. Create… 905 [OK]
centos/mysql-57-centos7 MySQL 5.7 SQL database server 92
mysql/mysql-cluster Experimental MySQL Cluster Docker images. Cr… 92
bitnami/mysql Bitnami MySQL Docker Image 65 [OK]
circleci/mysql MySQL is a widely used, open-source relation… 24
ubuntu/mysql MySQL open source fast, stable, multi-thread… 23
mysql/mysql-router MySQL Router provides transparent routing be… 23
centos/mysql-56-centos7 MySQL 5.6 SQL database server 21
google/mysql MySQL server for Google Compute Engine 19 [OK]
mysqlboy/mydumper mydumper for mysql logcial backups 3
mysqlboy/docker-mydumper docker-mydumper containerizes MySQL logical … 3
ibmcom/mysql-s390x Docker image for mysql-s390x 1
bitnami/mysqld-exporter 1
mysql MySQL is a widely used, open-source relation… 0 [OK]
ibmcom/tidb-ppc64le TiDB is a distributed NewSQL database compat… 0
mirantis/mysql 0
mysql/mysql-operator MySQL Operator for Kubernetes 0
cimg/mysql 0
phpmyadmin phpMyAdmin - A web interface for MySQL and M… 0 [OK]
mysqlboy/elasticsearch 0
mysqleatmydata/mysql-eatmydata 0
percona Percona Server is a fork of the MySQL relati… 0 [OK]
mysqled25519/mysqled25519 0
mariadb MariaDB Server is a high performing open sou… 0 [OK]
mysql/ndb-operator MySQL NDB Operator for Kubernetes 0
[root@192 ~]# docker pull mysql
Using default tag: latest
latest: Pulling from library/mysql
Digest: sha256:e9027fe4d91c0153429607251656806cc784e914937271037f7738bd5b8e7709
Status: Image is up to date for mysql:latest
docker.io/library/mysql:latest
[root@192 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest 605c77e624dd 7 weeks ago 141MB
tomcat latest fb5657adc892 8 weeks ago 680MB
mysql latest 3218b38490ce 2 months ago 516MB
hello-world latest feb5d9fea6a5 4 months ago 13.3kB
centos latest 5d0da3dc9764 5 months ago 231MB
elasticsearch 7.6.2 f29a1ee41030 23 months ago 791MB
elasticsearch latest 5acf0e8da90b 3 years ago 486MB
[root@192 ~]#
2 运行测试
运行启动mysql并设置账户密码:
[root@192 ~]# docker run -d --name mysql-tml -p 3366:3306 -e MYSQL_ROOT_PASSWORD=123456 mysql
b7842800b1cb46a7a79e01531d1e706fd4e54f8a6edadd07c8c32bd3abb41233
[root@192 ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
b7842800b1cb mysql "docker-entrypoint.s…" 4 seconds ago Up 3 seconds 33060/tcp, 0.0.0.0:3366->3306/tcp, :::3366->3306/tcp mysql-tml
3b66fa35905f elasticsearch:7.6.2 "/usr/local/bin/dock…" 6 minutes ago Up 6 minutes 0.0.0.0:3396->9200/tcp, :::3396->9200/tcp, 0.0.0.0:3397->9300/tcp, :::3397->9300/tcp elasticsearch-tml-7.6.2
bd6877cd46ce elasticsearch "/docker-entrypoint.…" 13 minutes ago Up 13 minutes 0.0.0.0:3392->9200/tcp, :::3392->9200/tcp, 0.0.0.0:3393->9300/tcp, :::3393->9300/tcp elasticsearch-tml
2f59536a92da tomcat "catalina.sh run" 2 hours ago Up 2 hours 0.0.0.0:3335->8080/tcp, :::3335->8080/tcp tomcat-tml
b8ae778bad8c nginx "/docker-entrypoint.…" 2 hours ago Up 2 hours 0.0.0.0:3334->80/tcp, :::3334->80/tcp nginx-tml
4ed9be7f96c8 centos "/bin/bash" 2 weeks ago Up 2 weeks inspiring_rhodes
cc886973b2cb centos "/bin/sh -c 'while t…" 2 weeks ago Up 2 weeks suspicious_borg
[root@192 ~]#
运行命令说明:
-p 3306:3306 :映射容器服务的 3306 端口到宿主机的 3306 端口,外部主机可以直接通过 宿主机ip:3306 访问到 MySQL 的服务。
MYSQL_ROOT_PASSWORD=123456:设置 MySQL 服务 默认账号root 用户的密码。
3 访问测试
进入容器,并通过账号root查看MySQL服务能否正常连接
[root@192 ~]# docker exec -it b7842800b1cb /bin/bash
root@b7842800b1cb:/# mysql -h localhost -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.27 MySQL Community Server - GPL
Copyright (c) 2000, 2021, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
Portaniner工具安装
Portaniner是Docker的图形化管理工具,类似的工具还有Rancher(CI/CD再用),使用时下载运行Portaniner镜像并运行,设置本机映射端口为8088,一键拉取镜像并运行容器
[root@192 ~]# docker run -d -p 8088:9000 --restart=always -v /var/run/docker.sock:/var/run/docker.sock --privileged=true portainer/portainer
Unable to find image 'portainer/portainer:latest' locally
latest: Pulling from portainer/portainer
94cfa856b2b1: Pull complete
49d59ee0881a: Pull complete
a2300fd28637: Pull complete
Digest: sha256:fb45b43738646048a0a0cc74fcee2865b69efde857e710126084ee5de9be0f3f
Status: Downloaded newer image for portainer/portainer:latest
78664208a245f44dd9cb9ea7c1fb8418431a7c36affb7e0dcfd110d21ce95196
[root@192 ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
78664208a245 portainer/portainer "/portainer" 13 seconds ago Up 12 seconds 0.0.0.0:8088->9000/tcp, :::8088->9000/tcp thirsty_gauss
b7842800b1cb mysql "docker-entrypoint.s…" 5 minutes ago Up 5 minutes 33060/tcp, 0.0.0.0:3366->3306/tcp, :::3366->3306/tcp mysql-tml
3b66fa35905f elasticsearch:7.6.2 "/usr/local/bin/dock…" 11 minutes ago Up 11 minutes 0.0.0.0:3396->9200/tcp, :::3396->9200/tcp, 0.0.0.0:3397->9300/tcp, :::3397->9300/tcp elasticsearch-tml-7.6.2
bd6877cd46ce elasticsearch "/docker-entrypoint.…" 18 minutes ago Up 18 minutes 0.0.0.0:3392->9200/tcp, :::3392->9200/tcp, 0.0.0.0:3393->9300/tcp, :::3393->9300/tcp elasticsearch-tml
2f59536a92da tomcat "catalina.sh run" 2 hours ago Up 2 hours 0.0.0.0:3335->8080/tcp, :::3335->8080/tcp tomcat-tml
b8ae778bad8c nginx "/docker-entrypoint.…" 3 hours ago Up 3 hours 0.0.0.0:3334->80/tcp, :::3334->80/tcp nginx-tml
4ed9be7f96c8 centos "/bin/bash" 2 weeks ago Up 2 weeks inspiring_rhodes
cc886973b2cb centos "/bin/sh -c 'while t…" 2 weeks ago Up 2 weeks suspicious_borg
[root@192 ~]#
第一次登录设置admin用户的密码:
登录后选择本地连接:
进入就可以看到自己的镜像和容器了:
以及我们刚开启的容器服务:
总结一下
经过之前的命令学习,今天这篇Blog主要是拿几个容器练手来熟悉之前的docker命令、进行一些简单的请求测试,并且通过工具面板可视化的去管理容器。到此为止,学习到的Docker容器的应用概念还是停留在单个组件的功能实现上,大型的分布式服务集群其实是融合了多种中间件去实现的,这到底是如何实现的,容器如何联合起来提供服务,还是比较好奇?所以还是比较期待后续容器编排一些高级概念的学习。
更多推荐
所有评论(0)