Docker部署nginx
拉取nginx并且展示
[root@localhost ~]# docker pull nginx
Using default tag: latest
latest: Pulling from library/nginx
a2abf6c4d29d: Pull complete
a9edb18cadd1: Pull complete
589b7251471a: Pull complete
186b1aaa4aa6: Pull complete
b4df32aa5a72: Pull complete
a0bcbecc962e: Pull complete
Digest: sha256:0d17b565c37bcbd895e9d92315a05c1c3c9a29f762b011a10c54a66cd53c9b31
Status: Downloaded newer image for nginx:latest
docker.io/library/nginx:latest
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest 605c77e624dd 6 months ago 141MB
hello-world latest feb5d9fea6a5 9 months ago 13.3kB
centos latest 5d0da3dc9764 9 months ago 231MB
暴露端口启动:
本机是3344,和docker里面的80映射
[root@localhost ~]# docker run -d --name nginx01 -p 3344:80 nginx
测试:
curl localhost:3344
显示下图表示访问成功:
端口暴露讲解:
部署tomcat
拉取tomcat
官方的:
docker pull tomcat:9.0
运行并且测试:
[root@localhost ~]# docker run -d -p 3355:8080 --name tomcat01 tomcat #默认是最新,所以需要指定版本号
Unable to find image 'tomcat:latest' locally
^C
[root@localhost ~]# docker run -d -p 3355:8080 --name tomcat01 tomcat:9.0
07d324d85900e7bd14d82f3d0ce9330ab45f44971eced296e5bc2d7df7f795c7
[root@localhost ~]# curl localhost:3355
<!doctype html><html lang="en"><head><title>HTTP Status 404 – Not Found</title><style type="text/css">body {font-family:Tahoma,Arial,sans-serif;} h1, h2, h3, b {color:white;background-color:#525D76;} h1 {font-size:22px;} h2 {font-size:16px;} h3 {font-size:14px;} p {font-size:12px;} a {color:black;} .line {height:1px;background-color:#525D76;border:none;}</style></head><body><h1>HTTP Status 404 – Not Found</h1><hr class="line" /><p><b>Type</b> Status Report</p><p><b>Description</b> The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.</p><hr class="line" /><h3>Apache Tomcat/9.0.56</h3></body></html>[root@localhost ~]#
发现是404,说明没有完全成功。
发现问题:
可以看到在这个容器里面ll命令也没有,webapps目录下面也没有东西。说明这个容器只有最基本的保障,还有一些内容不存在。
解决问题:
我们将webapps.dist下面的内容复制到webapps下面,操作如下。
再次测试就成功了。