Docker入門第六章

呂世昊 2021-08-15 15:34:54 阅读数:219

本文一共[544]字,预计阅读时长:1分钟~
docker 第六章 第六 六章

部署Nginx


#1.搜索鏡像 search 建議大家去docker搜索,可以看到幫助文檔
#2.下載鏡像 pull
#3.運行測試
[[email protected] ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest 08b152afcfae 3 weeks ago 133MB
centos latest 300e315adb2f 8 months ago 209MB
# -d 後臺運行
# --name 給容器命名
# -p 宿主機端口,容器內部端口
[[email protected] ~]# docker run -d --name nginx01 -p 3344:80 nginx
98fe864057ca7582ada2fc6b0b6f0fa3c40416481fb6ad7663931916315e84be
[[email protected] ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
98fe864057ca nginx "/docker-entrypoint.…" 13 seconds ago Up 6 seconds 0.0.0.0:3344->80/tcp, :::3344->80/tcp nginx01
[[email protected] ~]# curl localhost:3344
#進入容器
[[email protected] ~]# docker exec -it nginx01 /bin/bash
[email protected]:/# whereis nginx
nginx: /usr/sbin/nginx /usr/lib/nginx /etc/nginx /usr/share/nginx
[email protected]:/# cd /etc/nginx/
[email protected]:/etc/nginx# ls
conf.d fastcgi_params mime.types modules nginx.conf scgi_params uwsgi_params

部署Tomcat


#官方的使用
docker run -it --rm tomcat:9.0
#我們之前的啟動都是後臺,停止了容器之後,容器還是可以查到 docker run -it --rm,一般用來測試,用完就删除
#下載再啟動
docker pull tomcat
#啟動運行
docker run -d -p 3355:8080 --name tomcat01 tomcat
#測試訪問沒有問題
#進入容器
[[email protected] ~]# docker exec -it tomcat01 /bin/bash
#發現問題:
# 1.linux命令少了,2.webapps沒有文件,阿裏雲鏡像的原因,默認是最小的鏡像,所有不必要的都剔除掉
# 保證最小可運行環境

部署ES+Kibana


# es 暴露的端口很多!
# es 十分的耗內存
# es 的數據一啊不能需要放置到安全目錄!掛載
# --net somenetwork 是網絡配置
docker run -d --name elasticsearch --net somenetwork -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" elasticsearch:tag
#啟動 elaticsearch
docker run -d --name elasticsearch -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" elasticsearch:7.6.2
#測試一下es是否成功
[[email protected] ~]# curl localhost:9200
{
"name" : "566b9cc477be",
"cluster_name" : "docker-cluster",
"cluster_uuid" : "IAy-Zq6LTqa2dhC8LLCBSA",
"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"
}
#docker stats 查看cpu的狀態

可以看到我的虛擬機是1G內存,這個ElasticSearch占用了我545.6M,相當於占用了我56.11%的內存,我們可以對ES增加內存的限制,修改配置文件,

我們可以通過-e參數進行環境配置的修改,先關閉掉elasticsearch

#關閉掉剛剛啟動的ElasticSearch
[[email protected] ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
566b9cc477be elasticsearch:7.6.2 "/usr/local/bin/dock…" 37 minutes ago Up 36 minutes 0.0.0.0:9200->9200/tcp, :::9200->9200/tcp, 0.0.0.0:9300->9300/tcp, :::9300->9300/tcp elasticsearch
[[email protected] ~]# docker stop 566b9cc477be
#重新運行一個ElasticSearch實例
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
#啟動成功之後查看是否能够正常訪問
[[email protected] ~]# curl localhost:9200
{
"name" : "9ca8bdf59d48",
"cluster_name" : "docker-cluster",
"cluster_uuid" : "xgzM52tdTRyF-xqCzuPdBg",
"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"
}

然後再看一下內存占用的情况docker stats

可以看到此時占用內存才399M,依然正常訪問成功

版权声明:本文为[呂世昊]所创,转载请带上原文链接,感谢。 https://gsmany.com/2021/08/20210815153452204E.html