1、nginx的docker部署
1.1、下载nginx镜像
docker pull nginx
1.2、运行nginx镜像
[root@iZbp10j4antmyah3ya8nioZ ~]# docker run -d -p 80:80 --name mynginx01 nginx
1c48fb6b753f73e59740c4dbd86006e68f09d8c83ba2fe8c666cb3422ec56af7
[root@iZbp10j4antmyah3ya8nioZ ~]# docker ps
#运行后的结果如下
CONTAINER ID 1c48fb6b753f
IMAGE nginx
COMMAND "/docker-entrypoint.…"
CREATED 4 seconds ago
STATUS Up 3 seconds
PORTS 0.0.0.0:80->80/tcp
NAMES mynginx01
-d 代表后台运行
-p 80:80 代表端口映射 宿主机的80端口映射到容器的80端口
1.3、访问nginx
在本地宿主机上访问刚才运行的nginx实例
[root@iZbp10j4antmyah3ya8nioZ ~]# curl http://localhost:80
<!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>
通过外网访问
2、部署tomcat
2.1、下载tomcat镜像
docker pull tomcat:9.0
2.2、运行tomcat镜像
[root@iZbp10j4antmyah3ya8nioZ ~]# docker run -d -p 8080:8080 --name mytomcat01 tomcat:9.0
b9c5a058c3dfe6d8f92d1add38327338edb7971551145f2f1d964a75ee134ec0
[root@iZbp10j4antmyah3ya8nioZ ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
b9c5a058c3df tomcat:9.0 "catalina.sh run" 13 seconds ago Up 11 seconds 0.0.0.0:8080->8080/tcp mytomcat01
2.3、访问tomcat
可以看到tomcat已经起来了,但是要访问的资源不存在,需要把资源拷贝到相关的目录
docker exec -it 容器id /bin/bash
然后进入webapps,发现webapps下面没有任何资源,在webapps.dist目录下有资源。
把webapps.dist目录下的资源拷贝到webapps下面
root@b9c5a058c3df:/usr/local/tomcat# cp -r webapps.dist/* webapps
此时再次访问
标签:tomcat,部署,webapps,nginx,实例,docker,root,80 From: https://www.cnblogs.com/cplinux/p/17518938.html