- nginx安装
nginx的安装非常简单
docker run 先-d后台启动,-P自动端口映射
[root@localhost ~]# docker run -d -P --name nginx-test nginx
20ccd3f177aa317aaf813f8bb25f86b5fc1eacc20279c858ece9d063642c0160
[root@localhost ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
20ccd3f177aa nginx "/docker-entrypoint.?? About a minute ago Up About a minute 0.0.0.0:49162->80/tcp, :::49162->80/tcp nginx-test
b354fbcafadc nginx "/docker-entrypoint.?? 5 minutes ago Up 5 minutes 0.0.0.0:49161->80/tcp, :::49161->80/tcp gracious_meitner
9da5bc27c49d nginx "/docker-entrypoint.?? 2 days ago Up 9 minutes 0.0.0.0:49160->80/tcp, :::49160->80/tcp sad_mestorf
安装以后我们访问一下
nginx的index.html文件在/usr/share/nginx/html下,需要改动页面将文件放到目录下即可
[root@localhost ~]# docker exec -it 20ccd3f177aa /bin/bash
root@20ccd3f177aa:/# whereis nginx
nginx: /usr/sbin/nginx /usr/lib/nginx /etc/nginx /usr/share/nginx
root@20ccd3f177aa:/# cd /usr/share/nginx/html/
root@20ccd3f177aa:/usr/share/nginx/html# ls
50x.html index.html
每次发布网页都要进容器显得太麻烦,此时一般搭配上-v参数,挂载一个目录到容器里面nginx的对应目录,需要修改页面时,修改被挂载的卷即可
在本地root目录下创建了一个index.html的文件,文件内容是hello world,用-v参数将文件挂载到容器李nginx对应的发布目录
[root@localhost ~]# docker run -d -P -v /root/index.html:/usr/share/nginx/html/index.html nginx
b354fbcafadcce1c1082ea8c52446f6da629440e68297978147a48fb2f2e30df
[root@localhost ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
20ccd3f177aa nginx "/docker-entrypoint.?? 11 minutes ago Up 11 minutes 0.0.0.0:49162->80/tcp, :::49162->80/tcp nginx-test
b354fbcafadc nginx "/docker-entrypoint.?? 16 minutes ago Up 16 minutes 0.0.0.0:49161->80/tcp, :::49161->80/tcp gracious_meitner
9da5bc27c49d nginx "/docker-entrypoint.?? 2 days ago Up 19 minutes 0.0.0.0:49160->80/tcp, :::49160->80/tcp sad_mestorf
我们测试一下
ok,可以正常访问,接下来我们向/root/index.html里面追加一条hello docker,看看页面会不会变化
[root@localhost ~]# cat index.html
hello world
[root@localhost ~]# echo "hello docker">>index.html
[root@localhost ~]# cat index.html
hello world
hello docker
页面发生变化,操作生效
- tomcat安装
[root@localhost ~]# docker run -d -P --name tomcat-test tomcat
19bcbd2954eb9ead50dce1313b4249c35573d8afddf6446d7cc3d7965c6701b1
[root@localhost ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
19bcbd2954eb tomcat "catalina.sh run" 6 seconds ago Up 5 seconds 0.0.0.0:49163->8080/tcp, :::49163->8080/tcp tomcat-test
9da5bc27c49d nginx "/docker-entrypoint.?? 2 days ago Up 30 minutes 0.0.0.0:49160->80/tcp, :::49160->80/tcp sad_mestorf
访问一下
页面未找到。。。。 这里其实有一个坑,我们进到容器里面看看
root@19bcbd2954eb:/usr/local/tomcat# ls
BUILDING.txt CONTRIBUTING.md LICENSE NOTICE README.md RELEASE-NOTES RUNNING.txt bin conf lib logs native-jni-lib temp webapps webapps.dist work
root@19bcbd2954eb:/usr/local/tomcat# cd webapps
root@19bcbd2954eb:/usr/local/tomcat/webapps# pwd
/usr/local/tomcat/webapps
root@19bcbd2954eb:/usr/local/tomcat/webapps# ls
root@19bcbd2954eb:/usr/local/tomcat/webapps#
发现webapps里面没有东西,其实文件在webapps.dist里面
root@19bcbd2954eb:/usr/local/tomcat# cd webapps.dist/
root@19bcbd2954eb:/usr/local/tomcat/webapps.dist# ls
ROOT docs examples host-manager manager
root@19bcbd2954eb:/usr/local/tomcat/webapps.dist#
我们将webapps.dist的文件拷贝到webapps里面
root@19bcbd2954eb:/usr/local/tomcat# ls
BUILDING.txt CONTRIBUTING.md LICENSE NOTICE README.md RELEASE-NOTES RUNNING.txt bin conf lib logs native-jni-lib temp webapps webapps.dist work
root@19bcbd2954eb:/usr/local/tomcat# cp -r webapps.dist/* webapps
root@19bcbd2954eb:/usr/local/tomcat# cd webapps
root@19bcbd2954eb:/usr/local/tomcat/webapps# ls
ROOT docs examples host-manager manager
root@19bcbd2954eb:/usr/local/tomcat/webapps#
现在访问一下
页面出现