docker笔记4-部署
- 一、部署nginx
- 二、部署Tomcat
- 三、部署ES+Kibana
-
- [3.1 部署ES](#3.1 部署ES)
- [3.2 部署kibana](#3.2 部署kibana)
一、部署nginx
bash
docker search nginx #搜索nginx的最新版本
bash
docker pull nginx #这里可以指定nginx版本,如果不指定,那么就拉取最新版本latest
bash
docker run -d --name nginx01 -p 3344:80 nginx # -d: 运行后台进程,-p: 指定外界访问映射到容器的端口3344-> 80
bash
docker exec -it
bash
[root@ser878629168738 home]# curl localhost:3344
<!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>
bash
docker ps # 查看正在运行的镜像
bash
[root@ser878629168738 home]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
6c890549787f nginx "/docker-entrypoint...." 6 minutes ago Up 6 minutes 0.0.0.0:3344->80/tcp, :::3344->80/tcp nginx01
bash
docker exec -it nginx01 /bin/bash # 切入到容器中
二、部署Tomcat
bash
docker pull tomcat
bash
[root@ser878629168738 home]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest 605c77e624dd 2 years ago 141MB
tomcat latest fb5657adc892 2 years ago 680MB
centos latest 5d0da3dc9764 2 years ago 231MB
bash
docker run -d -p 3355:8080 --name tomcat01 tomcat #启动tomcat容器,命名为tomcat01
bash
[root@ser878629168738 home]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
11699886abdc tomcat "catalina.sh run" 4 seconds ago Up 3 seconds 0.0.0.0:3355->8080/tcp, :::3355->8080/tcp tomcat01
bash
docker exec -it 11699886abdc /bin/bash #切入到tomcat01中
三、部署ES+Kibana
3.1 部署ES
bash
docker run -d --name elasticsearch -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" elasticsearch:7.6.2 # 这种方式下载的es占用cpu严重,会直接导致操作很卡
bash
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 # 这种方式就极大地减少了es占用cpu的比例
bash
[root@ser878629168738 home]# docker stats 48ac2b94a32c
CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS
48ac2b94a32c elasticsearch02 0.00% 372.2MiB / 1.794GiB 20.26% 656B / 0B 96.9MB / 810kB 44
bash
[root@ser878629168738 home]# curl localhost:9200
{
"name" : "48ac2b94a32c",
"cluster_name" : "docker-cluster",
"cluster_uuid" : "uB1wJTFWSxmNnR7C1BGTtA",
"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"
}
3.2 部署kibana
bash
docker search kibana
bash
docker pull kibana #直接拉取最新kibana版本
bash
docker run --name kibana01 -e ELASTICSEARCH_HOSTS=http://xxxxxx:9200 -p 5601:5601 -d kibana # 启动一个新的Docker容器,名为kibana01,运行Kibana服务,并将其配置为连接到运行在http://xxxxx:9200的Elasticsearch实例。容器内的5601端口被映射到宿主机的5601端口,以便用户可以通过浏览器访问Kibana的Web界面。容器将以分离模式在后台运行。
可以通过http://xxxxxx:5601
来访问kibana