Docker部署Nginx、Tomcat

部署Nginx

#1. 搜索镜像
sudo docker search nginx

#2. 下载镜像
sudo docker pull nginx

#3. 查看是否存在镜像
sudo docker images

#4. 启动容器
## -d:后台启动
## --name:容器名字
## -p:容器端口与主机端口映射,3344是主机端口,80容器端口
sudo docker run -d --name nginx01 -p 3344:80 nginx

#5. 查看容器
sudo docker ps

#6. 测试是否开启端口
ubuntu@VM-0-13-ubuntu:/home$ curl localhost:3344
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
    body {
         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>


#7. 进入容器
ubuntu@VM-0-13-ubuntu:/home$ sudo docker exec -it nginx01 /bin/bash
root@69d24544c396:/# whereis nginx
nginx: /usr/sbin/nginx /usr/lib/nginx /etc/nginx /usr/share/nginx
root@69d24544c396:/# cd /etc/nginx
root@69d24544c396:/etc/nginx# ls
conf.d	fastcgi_params	koi-utf  koi-win  mime.types  modules  nginx.conf  scgi_params	uwsgi_params  win-utf

#8. 停止容器
ubuntu@VM-0-13-ubuntu:/home$ sudo docker stop 69d24544c396
69d24544c396

端口映射的概念

端口映射

思考问题
我们每次改动nginx配置文件,都需要进入容器内部?十分麻烦,我要是可以在容器外部提供一个映射路径,达到在容器修改文件名,容器内部就可以自动修改?
解决方案: -V 数据卷技术

部署Tomcat

# 官方的使用
docker run -it --rm tomcat:9.0

## 我们之前的启动都是后台,停止了容器之后,容器还是可以查到,docker run -it --rm,一般用来测试的,用完就删除,docker run 会自动拉取镜像

# 下载Tomcat
docker pull tomcat

# 启动运行
ubuntu@VM-0-13-ubuntu:/home$ sudo docker run -d -p 3344:8080 --name tomcat01 tomcat
ef7308eda36e5e329e67898412f3027887a29b911e7036a6a1df098ceec1761b

# 测试访问没有问题

# 进入容器
ubuntu@VM-0-13-ubuntu:/home$ sudo docker exec -it ef7308eda36e /bin/bash
root@ef7308eda36e:/usr/local/tomcat

# 发现问题:1、Linux命令少了    2、没有webapps。阿里云镜像的原因,默认是最小的镜像,所有不必要的都剔除掉,保证最小可运行的环境

# 复制webapps.dist 中的所有文件到 webapps
cp -r webapps.dist/* webapps/

思考问题:我们以后要部署项目,如果每次都要进入容器是不是十分麻烦,我要是可以在容器外部提供一个映射路径,webapps,我们在外部放置项目,就自动同步到内部就好了

部署 ES + Kibana

# es 暴露的端口很多
# es 十分的耗内存
# es 的数据一般需要放置到安全目录!使用挂载
# --net somenetwork 网络配置
# 启动 elasticsearch
docker run -d --name elasticsearch -p 9300:9300 -e "doscovery.type=single-node" elasticsearch:7.6.2

# 启动了 Linux就卡住了 docker stats 查看cpu的状态

# 需要加内存限制
原文地址:https://www.cnblogs.com/lxlhelloworld/p/14286466.html