Docker上部署服务应用
部署Nginx
1 | docker pull nginx //下载Nginx镜像 |
1 | docker run -d --name="MyNginx01" -p 3090:80 nginx //后台方式,以外部主机端口3090映射容器端口80,运行Nginx,容器别名为MyNginx01 |
1 | curl localhost:3090 //在外部主机测试容器Nginx服务 |
1 | docker exec -it 53c01c475a1e /bin/bash //进入容器 |
部署Tomcat
1 | docker run -it --rm -p 8888:8080 tomcat:9.0 //交互方式,以外部主机端口8888映射容器端口8080,运行Tomcat。用完后,退出容器后,立即删除镜像,一般用于测试使用。 |
1 | docker pull tomcat //下载Tomcat镜像 |
1 | docker run -d --name="MyTomcat" -p 8888:8080 tomcat //后台方式,以外部主机端口8888映射容器端口8080,运行Tomcat,容器别名为MyTomcat |
1 | curl localhost:8888 //测试访问显示404 |
此处要注意,【有坑】!
1 | docker exec -it 2dd5319e4047 /bin/bash //进入容器 |
1 | cp -r webapps.dist/* webapps //将webapps.dist目录下的所以文件,拷贝到webapps目录 |
1 | curl localhost:8888 //测试访问显示正常 |
部署Elasticsearch
1 | docker run -d --name="MyElasticsearch" -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" elasticsearch:7.6.2 //下载并运行elasticsearch |
1 | docker stats //监控查看docker内存情况 |
1 | localhost:9200 //测试Elasticsearch |
1 | docker stop 17079ad436b2 //停止容器 |
1 | docker run -d --name="MyElasticsearch02" -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" -e ES_JAVA_OPTS="-Xms64m -Xmx512m" elasticsearch:7.6.2 //设置Elasticsearch内存限制,-e ES_JAVA_OPTS="-Xms64m -Xmx512m",最大内存512MB,最小64MB;容器别名:MyElasticsearch02 |
1 | curl localhost:9200 //测试正常 |
All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.