文章目录
- 1.步骤如下:
1.步骤如下:
- (1)创建映射80端口的交互式容器
root@ubuntu:/home/jiwangreal# docker run -p 80 --name web -i -t ubuntu /bin/bash
root@a35b9bee17c1:/# apt-get update
- (2)安装Nginx服务
root@a35b9bee17c1:/# apt-get install -y nginx
如果安装nginx成功的话:可以看到nginx/的目录
root@d0cc272587eb:/etc# cd /etc/n
networks nginx/ nsswitch.conf
- (3)安装文本编辑器vim
root@a35b9bee17c1:/# apt-get install -y vim
- (4)创建静态页面
root@a35b9bee17c1:/# mkdir -p /var/www/html
root@a35b9bee17c1:/# cd /var/www/html/
root@a35b9bee17c1:/var/www/html# vim index.html
内容如下:
<html>
<head>
<title>Nginx in Docker</title>
</head>
<body>Hello Docker</body>
</html>
- (5)修改Nginx的配置文件
root@d0cc272587eb:/etc/nginx/sites-enabled# vim /etc/nginx/sites-enabled/default
保证root的目录进行修改了
# include snippets/snakeoil.conf;
root /var/www/html;
# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html;
server_name _;
- (6)运行Nginx
root@d0cc272587eb:/etc/nginx/sites-enabled# cd /
root@d0cc272587eb:/# nginx
root@d0cc272587eb:/# ps -ef
UID PID PPID C STIME TTY TIME CMD
root 1 0 0 03:09 pts/0 00:00:00 /bin/bash
root 1030 1 0 06:31 ? 00:00:00 nginx: master process nginx
www-data 1031 1030 0 06:31 ? 00:00:00 nginx: worker process
root 1032 1 0 06:31 pts/0 00:00:00 ps -ef
查看容器的映射端口,这里为32768
root@d0cc272587eb:/# root@ubuntu:/home/jiwangreal# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
d0cc272587eb ubuntu "/bin/bash" 3 hours ago Up 3 hours 0.0.0.0:32768->80/tcp web
root@ubuntu:/home/jiwangreal# docker port web
80/tcp -> 0.0.0.0:32768
- (7)验证网站访问
表示访问成功!!
root@ubuntu:/home/jiwangreal# curl http://127.0.0.1:32768
<html>
<head>
<title>Nginx in Docker</title>
</head>
<body>Hello Docker</body>
</html>
root@ubuntu:/home/jiwangreal#