docker中利用nginx部署静态网站
1.创建一个名为web的交互式容器,端口为80
# docker run -p 80 --name web -it centos /bin/bash
2.在容器中安装nginx
# rpm -ivh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm //将nginx放到yum repro库中
# yum install nginx -y
3.安装vim编辑器
# yum install vim -y
4.创建一个静态网页
# mkdir -p /var/www/html
# cd /var/www/html
# vim index.html
<html>
<head>
<title>nginx in docker</title>
</head>
<body>
<h1> this is a web application in docker </h1>
</body>
</html>
5.修改nginx的配置
# whereis nginx
# ls /etc/nginx/
# ls /etc/nginx/conf.d/
# vim /etc/nginx/conf.d/default.conf //把root后面的路径修改为我们最初创建的静态网站的路径:/var/www/html
6.运行nginx
# cd / //切换到根目录: cd /
# nginx //用nginx命令启动nginx
# ps -ef //用ps -ef查看nginx服务是否启动
7.验证是否成功
使用ctrl+p和ctrl+q退出容器而不停止容器的运行,即将命令行从docker回到linux上
# docker ps -a
# curl http://127.0.0.1:32774