一、Docker 安裝 Nginx
# 1、搜索鏡像
[root@localhost home]# docker search nginx
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
nginx Official build of Nginx. 18765 [OK]
# 2、拉取鏡像
[root@localhost home]# 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
# 3、啟動(dòng)容器
[root@localhost home]# docker run -d --name nginx01 -p 80:80 nginx
902918d2f1c36de403e62fc8eb15ef873051838aabb838c16d14c1d6c2dc3b1a
# 4、測(cè)試訪問(wèn)
[root@localhost home]# curl localhost:80
<!DOCTYPE html>
<html>
<title>Welcome to nginx!</title>
//........
</html>
# 5、進(jìn)入容器
[root@localhost home]# docker exec -it nginx01 /bin/bash
root@902918d2f1c3:/# whereis nginx # 尋找 nginx
nginx: /usr/sbin/nginx /usr/lib/nginx /etc/nginx /usr/share/nginx
root@902918d2f1c3:/# cd /usr/share/nginx/ # nginx 的路徑
root@902918d2f1c3:/usr/share/nginx# ls
html
root@902918d2f1c3:/usr/share/nginx# cd html/ # 首頁(yè)的位置
root@902918d2f1c3:/usr/share/nginx/html# ls
50x.html index.html
root@902918d2f1c3:/usr/share/nginx/html# cat index.html
<!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 >nginx.org</a>.<br/>
Commercial support is available at
<a >nginx.com</a>.</p>
<p><em>Thank you for using nginx.</em></p>
</body>
</html>
二、Docker 安裝 Tomcat
# 官方文檔解釋
# -it :交互模式
# --rm:容器啟動(dòng)成功并退出以后容器就自動(dòng)移除,一般在測(cè)試情況下使用!
docker run -it --rm tomcat:9.0
# 1、下載tomcat鏡像
docker pull tomcat
# 2、啟動(dòng)
docker run -d -p 8080:8080 --name tomcat9 tomcat
# 3、進(jìn)入tomcat
docker exec -it tomcat9 /bin/bash
# 4、思考:我們以后要部署項(xiàng)目,還需要進(jìn)入容器中,是不是十分麻煩,要是有一種技術(shù),可以將容器內(nèi)和我們Linux進(jìn)行映射掛載就好了?我們后面會(huì)將數(shù)據(jù)卷技術(shù)來(lái)進(jìn)行掛載操作,也是一個(gè)核心內(nèi)容,這里大家先聽(tīng)聽(tīng)名詞就好,我們很快就會(huì)講到!
三、Docker 部署 es+kibana
# 我們啟動(dòng) es 這種容器需要考慮幾個(gè)問(wèn)題
# 1、端口暴露問(wèn)題 9200、9300
# 2、數(shù)據(jù)卷的掛載問(wèn)題 data、plugins、conf
# 3、吃內(nèi)存 - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
# 擴(kuò)展命令
docker stats 容器id # 查看容器的 cpu 內(nèi)存和網(wǎng)絡(luò)狀態(tài)
# 1、啟動(dòng) es 測(cè)試
docker run -d --name elasticsearch -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" elasticsearch:7.6.2
# 2、啟動(dòng)之后很卡,使用 docker stats 容器 id 查看下 cpu 狀態(tài) ,發(fā)現(xiàn)占用的很大
CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS
214e2ced819d elasticsearch 0.42% 1.248GiB / 3.682GiB 33.90% 656B / 0B 115MB / 828kB 46
# 3、測(cè)試訪問(wèn)
[root@localhost home]# curl localhost:9200
{
"name" : "214e2ced819d",
"cluster_name" : "docker-cluster",
"cluster_uuid" : "ddHka58_T1CoTrl8-Kltjw",
"version" : {
"number" : "7.6.2",
"build_flavor" : "default",
"build_type" : "docker",
"build_hash" : "ef48eb35cf30adf4db14086e8aabd07ef6fb113f",
"build_date" : "2020-03-26T06:34:37.794943Z",
"build_snapshot" : false,
"lucene_version" : "8.4.0",
"minimum_wire_compatibility_version" : "6.8.0",
"minimum_index_compatibility_version" : "6.0.0-beta1"
},
"tagline" : "You Know, for Search"
}
# 4、增加上內(nèi)存限制啟動(dòng)
docker run -d --name elasticsearch02 -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" -e ES_JAVA_OPTS="-Xms64m -Xmx512m" elasticsearch:7.6.2
# 5、啟動(dòng)之后,使用 docker stats 查看下cpu狀態(tài)
CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS
60f6c9a3d757 elasticsearch02 0.62% 396MiB / 3.682GiB 10.50% 656B / 0B 30.2MB / 836kB 46
# 6、測(cè)試訪問(wèn),效果一樣,ok!
[root@localhost home]# curl localhost:9200
{
"name" : "60f6c9a3d757",
"cluster_name" : "docker-cluster",
"cluster_uuid" : "-mC76kR-RaCjxWTay9basA",
"version" : {
"number" : "7.6.2",
"build_flavor" : "default",
"build_type" : "docker",
"build_hash" : "ef48eb35cf30adf4db14086e8aabd07ef6fb113f",
"build_date" : "2020-03-26T06:34:37.794943Z",
"build_snapshot" : false,
"lucene_version" : "8.4.0",
"minimum_wire_compatibility_version" : "6.8.0",
"minimum_index_compatibility_version" : "6.0.0-beta1"
},
"tagline" : "You Know, for Search"
}
四、可視化
????????Portainer 是 Docker 的圖形化管理工具,提供狀態(tài)顯示面板、應(yīng)用模板快速部署、容器鏡像網(wǎng)絡(luò)數(shù)據(jù)卷的基本操作(包括上傳下載鏡像,創(chuàng)建容器等操作)、事件日志顯示、容器控制臺(tái)操作、Swarm 集群和服務(wù)等集中管理和操作、登錄用戶管理和控制等功能。功能十分全面,基本能滿足中小型單位對(duì)容器管理的全部需求。
????????如果僅有一個(gè) docker 宿主機(jī),則可使用單機(jī)版運(yùn)行,Portainer 單機(jī)版運(yùn)行十分簡(jiǎn)單,只需要一條語(yǔ)句即可啟動(dòng)容器,來(lái)管理該機(jī)器上的 docker 鏡像、容器等數(shù)據(jù)。
docker run -d -p 8088:9000 --restart=always -v /var/run/docker.sock:/var/run/docker.sock --privileged=true portainer/portainer
????????訪問(wèn)方式:http://IP:8088,首次登陸需要注冊(cè)用戶,給 admin 用戶設(shè)置密碼:?
????????單機(jī)版這里選擇 local 即可,選擇完畢,點(diǎn)擊 Connect 即可連接到本地 docker:
????????登錄成功,可以點(diǎn)擊 local 看看本地的 docker 信息。文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-584640.html
文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-584640.html
到了這里,關(guān)于Docker 安裝 nginx 和 tomcat 并部署 es + kibana 和可視化的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!