部署Nginx
1.下载镜像:docker pull Nginx
2.运行测试:
[root@iZwz9g94s1ylux707g0qu3Z /]# docker images #查看镜像
REPOSITORY TAG IMAGE ID CREATED SIZE
MysqL 5.7 a70d36bc331a 3 weeks ago 449MB
MysqL latest c8562eaf9d81 3 weeks ago 546MB
Nginx latest f6d0b4767a6c 4 weeks ago 133MB
centos latest 300e315adb2f 2 months ago 209MB
hello-world latest bf756fb1ae65 13 months ago 13.3kB
[root@iZwz9g94s1ylux707g0qu3Z /]# docker run -d --name Nginx01 -p 3344:80 Nginx #运行测试
afd1aa8bc5f9326b745a03abfb64da79113470c32460fdb0c48beda28dd70736
[root@iZwz9g94s1ylux707g0qu3Z /]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS POR
afd1aa8bc5f9 Nginx "/docker-entrypoint.…" 5 seconds ago Up 4 seconds 0.0
[root@iZwz9g94s1ylux707g0qu3Z /]# curl localhost:3344 #本机测试
<!DOCTYPE html>
<html>
<head>
<title>Welcome to Nginx!</title>
<style>
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>
重点是:docker run -d --name Nginx01 -p 3344:80 Nginx
其中-p 3344:80
意思是 -p 宿主机端口:容器内部端口
端口暴露理解:
docker exec -it Nginx01 /bin/bash
进入之后,可以通过:
whereis Nginx01
来查看相应的配置文件位置
[root@iZwz9g94s1ylux707g0qu3Z /]# docker exec -it Nginx01 /bin/bash
root@afd1aa8bc5f9:/# whereis Nginx01
Nginx01:
root@afd1aa8bc5f9:/# whereis Nginx
Nginx: /usr/sbin/Nginx /usr/lib/Nginx /etc/Nginx /usr/share/Nginx
root@afd1aa8bc5f9:/usr/share/Nginx# cd /etc/Nginx #html页面就存在这个/Nginx下面
root@afd1aa8bc5f9:/etc/Nginx# ls
conf.d koi-utf mime.types Nginx.conf uwsgi_params
fastcgi_params koi-win modules scgi_params win-utf
部署tomcat
1.下载镜像:docker pull tomcat
2.运行测试:docker run -d -p 3355:8080 --name tomcat01 tomcat
(安全组和防火墙要开放3355端口)。
这个时候发现,通过外网访问3355端口时,出现404错误!
进入tomcat容器查看:docker exec -it tomcat01 /bin/bash
[root@iZwz9g94s1ylux707g0qu3Z home]# docker exec -it tomcat01 /bin/bash
root@78de0b9024e0:/usr/local/tomcat# ls
BUILDING.txt NOTICE RUNNING.txt lib temp work
CONTRIBUTING.md README.md bin logs webapps
LICENSE RELEASE-NOTES conf native-jni-lib webapps.dist
root@78de0b9024e0:/usr/local/tomcat# ls -al
total 128
drwxr-xr-x 1 root root 30 Jan 13 08:25 .
drwxr-xr-x 1 root root 20 Jan 13 08:19 ..
-rw-r--r-- 1 root root 18982 Dec 3 11:48 BUILDING.txt
-rw-r--r-- 1 root root 5409 Dec 3 11:48 CONTRIBUTING.md
-rw-r--r-- 1 root root 57092 Dec 3 11:48 LICENSE
-rw-r--r-- 1 root root 2333 Dec 3 11:48 NOTICE
-rw-r--r-- 1 root root 3257 Dec 3 11:48 README.md
-rw-r--r-- 1 root root 6898 Dec 3 11:48 RELEASE-NOTES
-rw-r--r-- 1 root root 16507 Dec 3 11:48 RUNNING.txt
drwxr-xr-x 2 root root 4096 Jan 13 08:25 bin
drwxr-xr-x 1 root root 40 Feb 13 09:41 conf
drwxr-xr-x 2 root root 4096 Jan 13 08:25 lib
drwxrwxrwx 1 root root 177 Feb 13 09:41 logs
drwxr-xr-x 2 root root 134 Jan 13 08:25 native-jni-lib
drwxrwxrwx 2 root root 30 Jan 13 08:25 temp
drwxr-xr-x 2 root root 6 Jan 13 08:25 webapps
drwxr-xr-x 7 root root 81 Dec 3 11:45 webapps.dist
drwxrwxrwx 2 root root 6 Dec 3 11:43 work
root@78de0b9024e0:/usr/local/tomcat# cd webapps
root@78de0b9024e0:/usr/local/tomcat/webapps# ls #webapps目录下没有东西
root@78de0b9024e0:/usr/local/tomcat/webapps#
发现存放项目的/tomcat/webapps文件夹下没有东西!这也是导致出现404错误的原因。
解决:只需要把 /webapps.dist文件下的东西拷贝到/webapps文件下就可以访问tomcat了
root@78de0b9024e0:/usr/local/tomcat# cd webapps.dist
root@78de0b9024e0:/usr/local/tomcat/webapps.dist# ls
ROOT docs examples host-manager manager
root@78de0b9024e0:/usr/local/tomcat/webapps.dist# cd ..
root@78de0b9024e0:/usr/local/tomcat# cp -r webapps.dist/* webapps
root@78de0b9024e0:/usr/local/tomcat# cd webapps
root@78de0b9024e0:/usr/local/tomcat/webapps# ls
ROOT docs examples host-manager manager
如果自己写项目的话,只需要自己在/webapps文件下改就可以了。