- 部署Nginx
1.1 搜索并下载Nginx镜像
$ docker search nginx
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
nginx Official build of Nginx. 14552 [OK]
$ docker pull nginx
Using default tag: latest
latest: Pulling from library/nginx
45b42c59be33: Pull complete
f201eed3edb3: Pull complete
32b8d3b748d6: Pull complete
541dfa80698c: Pull complete
12d7728b7b65: Pull complete
d7616c5653f5: Pull complete
Digest: sha256:d5b6b094a614448aa0c48498936f25073dc270e12f5fcad5dc11e7f053e73026
Status: Downloaded newer image for nginx:latest
1.2 启动镜像
#-d 后台运行,--name 给容器命名,-p 宿主机端口:容器内部端口
$ docker run -d --name nginx01 -p 3344:80 nginx
694150b823cd070ed8d4ec5b8d23cc69107dbcc0fc115807e7f9002bdad7235a
docker $ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
694150b823cd nginx "/docker-entrypoin..." 10 hours ago Up 6 seconds 0.0.0.0:3344->80/tcp nginx01
1.3 本地测试
$ curl localhost:3344
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
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.4 进入容器
$ docker exec -it 694150b823cd /bin/bash
root@694150b823cd:/# whereis nginx
nginx: /usr/sbin/nginx /usr/lib/nginx /etc/nginx /usr/share/nginx
root@694150b823cd:/# cd /etc/nginx
root@694150b823cd:/etc/nginx# ls
conf.d fastcgi_params koi-utf koi-win mime.types modules nginx.conf scgi_params uwsgi_params win-utf
- 部署Tomcat
2.1 安装运行tomcat镜像
#--rm 一般用来测试,用完即删除容器
$ docker run -it --rm tomcat:9.0
$ docker ps -a #这里就看不到刚才运行的tomcat
#启动镜像
$ docker run -d -p 3355:8080 --name tomcat01 tomcat:9.0
0542152f2575fb53c4f2d534ffca6301ea19e4b6102b9d0ce20eca5fa7655d3b
2.2 本地测试
启动成功,只是找不到页面:
$ curl localhost:3355
<!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/9.0.44</h3></body></html>
进入容器,发现webapps为空,内容都在webapps.dist里,将它们拷贝到webapps里面即可。
$ docker exec -it tomcat01 /bin/bash
root@0542152f2575:/usr/local/tomcat# cd webapps
root@0542152f2575:/usr/local/tomcat/webapps# ls
root@0542152f2575:/usr/local/tomcat/webapps# cd ../webapps.dist
root@0542152f2575:/usr/local/tomcat/webapps.dist# ls
ROOT docs examples host-manager manager
root@0542152f2575:/usr/local/tomcat/webapps.dist# cp -r ./* ../webapps/
再次打开页面测试localhost:3355
localhost:3355
- 部署Elasticsearch
3.1 特别之处
es暴露的端口很多
es十分的耗内存
3.2 下载并运行
$ docker run -d --name elasticsearch -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" elasticsearch:7.11.1
...
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
cb739d0a9214 elasticsearch:7.11.1 "/bin/tini -- /usr..." 10 hours ago Up 12 seconds 0.0.0.0:9200->9200/tcp, 0.0.0.0:9300->9300/tcp elasticsearch
3.3 测试es是否成功
$ curl localhost:9200
{
"name" : "cb739d0a9214",
"cluster_name" : "docker-cluster",
"cluster_uuid" : "IWKZYWH5SU66bbrZuQiyFw",
"version" : {
"number" : "7.11.1",
"build_flavor" : "default",
"build_type" : "docker",
"build_hash" : "ff17057114c2199c9c1bbecc727003a907c0db7a",
"build_date" : "2021-02-15T13:44:09.394032Z",
"build_snapshot" : false,
"lucene_version" : "8.7.0",
"minimum_wire_compatibility_version" : "6.8.0",
"minimum_index_compatibility_version" : "6.0.0-beta1"
},
"tagline" : "You Know, for Search"
}
3.4 查看内存使用情况,非常耗内存。
$ docker stats cb739d0a9214
CONTAINER CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS
cb739d0a9214 1.85% 1.226 GiB / 1.952 GiB 62.78% 1.99 kB / 2.09 kB 10.6 MB / 467 kB 48
3.5 关闭,增加内存的限制,再启动。可以看到占用内存减少了。
$ docker run -d --name elasticsearch02 -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" -e ES_JAVA_OPTS="-Xms64m -Xmx512m" elasticsearch:7.11.1
$ docker stats ee22dfabf98cdd5624b236cdfbbaa41e6939a7187d76e91957e8cf52bae17e38
CONTAINER CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS
ee22dfabf98cdd5624b236cdfbbaa41e6939a7187d76e91957e8cf52bae17e38 1.68% 406.2 MiB / 1.952 GiB 20.32% 986 B / 788 B 500 kB / 1.44 MB 49
网友评论