激情久久久_欧美视频区_成人av免费_不卡视频一二三区_欧美精品在欧美一区二区少妇_欧美一区二区三区的

服務(wù)器之家:專注于服務(wù)器技術(shù)及軟件下載分享
分類導(dǎo)航

云服務(wù)器|WEB服務(wù)器|FTP服務(wù)器|郵件服務(wù)器|虛擬主機(jī)|服務(wù)器安全|DNS服務(wù)器|服務(wù)器知識(shí)|Nginx|IIS|Tomcat|

服務(wù)器之家 - 服務(wù)器技術(shù) - 服務(wù)器知識(shí) - 在Docker容器中部署靜態(tài)網(wǎng)頁(yè)的方法教程

在Docker容器中部署靜態(tài)網(wǎng)頁(yè)的方法教程

2021-01-27 17:56興國(guó)First 服務(wù)器知識(shí)

這篇文章主要給大家介紹了在Docker容器中部署靜態(tài)網(wǎng)頁(yè)的方法教程,文中介紹的非常詳細(xì),對(duì)大家具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來(lái)一起看看吧。

前言

一般我們?cè)谠L問(wèn)容器時(shí)需要通過(guò)容器的端口來(lái)訪問(wèn),那如何設(shè)置容器的端口映射呢?

我們通過(guò)以下命令來(lái)設(shè)置:

?
1
docker run -p ip:hostport:containerport [--name] [-i] [-t] 鏡像名 [command][arg...]
  • ip:表示宿主機(jī)ip
  • hostport:宿主機(jī)端口號(hào)
  • containerport:容器端口號(hào)

設(shè)置的方式有以下幾種:

containerport,指定容器端口號(hào),宿主機(jī)端口隨機(jī)生成

?
1
[root@localhost ~]# docker run -p 80 --name web_test -i -t 80864d42dd23  hub.c.163.com/library/ubuntu /bin/bash

hostport:containerport映射主機(jī)端口和容器端口

?
1
[root@localhost ~]# docker run -p 8080:80 --name web_test -i -t 80864d42dd23  hub.c.163.com/library/ubuntu /bin/bash

ip::containerport設(shè)置主機(jī)的隨機(jī)端口到容器端口

?
1
[root@localhost ~]# docker run -p 0.0.0.0::80 --name web_test -i -t 80864d42dd23  hub.c.163.com/library/ubuntu /bin/bash

ip:hostport:containerport映射指定地址的指定端口到容器的指定端口

?
1
[root@localhost ~]# docker run -p 0.0.0.0:8080:80 --name web_test -i -t 80864d42dd23  hub.c.163.com/library/ubuntu /bin/bash

下面通過(guò)nginx在容器部署靜態(tài)網(wǎng)頁(yè),通過(guò)以下步驟

      - 創(chuàng)建80映射端口的交互式容器

      - 安裝nginx

      - 安裝文本編輯器vim

      - 創(chuàng)建靜態(tài)網(wǎng)頁(yè)

      - 運(yùn)行nginx

      - 驗(yàn)證網(wǎng)頁(yè)

示例如下(如果安裝完ubuntu后不能安裝nginx進(jìn)行apt-get update):

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
[root@localhost ~]# docker run -p 80 --name static_test -i -t hub.c.163.com/library/ubuntu /bin/bash
root@25fcbf6e953d:/# apt-get install -y nginx
reading package lists... done
building dependency tree 
reading state information... done
e: unable to locate package nginx
root@25fcbf6e953d:/# apt-get update  
get:1 http://archive.ubuntu.com/ubuntu xenial inrelease [247 kb]
get:2 http://archive.ubuntu.com/ubuntu xenial-updates inrelease [102 kb]
**中間日志省略。。。。。。。。。。**                  
fetched 24.9 mb in 9s (2717 kb/s)                                
reading package lists... done
root@25fcbf6e953d:/# apt-get install -y nginx
reading package lists... done
building dependency tree 
reading state information... done
**安裝日志省略。。。。。。。。。。**

然后安裝vim:

?
1
2
3
4
5
6
root@25fcbf6e953d:/# apt-get install -y vim
reading package lists... done
building dependency tree 
reading state information... done
the following additional packages will be installed:
**安裝日志省略。。。。。。。。。。**

然后建立存放靜態(tài)文件的目錄,并創(chuàng)建一個(gè)簡(jiǎn)單的html文件:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
root@25fcbf6e953d:/# mkdir -p /var/www/html
root@25fcbf6e953d:/#
root@25fcbf6e953d:/# cd /var/www/html/
root@25fcbf6e953d:/var/www/html# vim index.html
root@25fcbf6e953d:/var/www/html# ll
total 8
drwxr-xr-x. 2 root root 53 mar 13 05:02 ./
drwxr-xr-x. 3 root root 17 mar 13 04:50 ../
-rw-r--r--. 1 root root 79 mar 13 05:02 index.html
-rw-r--r--. 1 root root 612 mar 13 04:51 index.nginx-debian.html
root@25fcbf6e953d:/var/www/html# cat index.html
<html>
<body>
<h1>
  this is the first docker static file
</h1>
</body>
</html>
root@25fcbf6e953d:/var/www/html#

找到nginx的安裝目錄,更改default的root值為剛才創(chuàng)建的目錄:

?
1
2
3
4
5
6
7
8
9
root@25fcbf6e953d:/var/www/html# whereis nginx
nginx: /usr/sbin/nginx /etc/nginx /usr/share/nginx
root@25fcbf6e953d:/var/www/html# cd /etc/nginx/sites-enabled/
root@25fcbf6e953d:/etc/nginx/sites-enabled# ll
total 4
drwxr-xr-x. 2 root root 20 mar 13 04:51 ./
drwxr-xr-x. 6 root root 4096 mar 13 04:51 ../
lrwxrwxrwx. 1 root root 34 mar 13 04:51 default -> /etc/nginx/sites-available/default
root@25fcbf6e953d:/etc/nginx/sites-enabled# vim default

在Docker容器中部署靜態(tài)網(wǎng)頁(yè)的方法教程

然后啟動(dòng)nginx,查看容器進(jìn)程:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
root@25fcbf6e953d:/etc/nginx/sites-enabled# nginx
root@25fcbf6e953d:/etc/nginx/sites-enabled# ps -ef
uid  pid ppid c stime tty   time cmd
root   1  0 0 04:48 ?  00:00:00 /bin/bash
root  827  1 0 05:06 ?  00:00:00 nginx: master process nginx
www-data 828 827 0 05:06 ?  00:00:00 nginx: worker process
www-data 829 827 0 05:06 ?  00:00:00 nginx: worker process
www-data 830 827 0 05:06 ?  00:00:00 nginx: worker process
www-data 831 827 0 05:06 ?  00:00:00 nginx: worker process
www-data 832 827 0 05:06 ?  00:00:00 nginx: worker process
www-data 833 827 0 05:06 ?  00:00:00 nginx: worker process
www-data 834 827 0 05:06 ?  00:00:00 nginx: worker process
www-data 835 827 0 05:06 ?  00:00:00 nginx: worker process
root  836  1 0 05:07 ?  00:00:00 ps -ef
root@25fcbf6e953d:/etc/nginx/sites-enabled#

然后按ctrl+p,ctrl+q退出交互式容器。

使用docker ps查看容器的端口和運(yùn)行情況,也可以通過(guò)dcoker port 鏡像名查看:

?
1
2
3
4
5
6
root@localhost ~]# docker ps
container id  image       command     created    status    ports     names
25fcbf6e953d  hub.c.163.com/library/ubuntu "/bin/bash"    18 minutes ago  up 18 minutes  0.0.0.0:32772->80/tcp static_test
[root@localhost ~]# docker port static_test
80/tcp -> 0.0.0.0:32772
[root@localhost ~]#

可以看到容器的80端口映射到注解的32772端口。

通過(guò)curl訪問(wèn)創(chuàng)建的index.html文件:

?
1
2
3
4
5
6
7
8
9
[root@localhost ~]# curl http://127.0.0.1:32772/index.html
<html>
<body>
<h1>
  this is the first docker static file
</h1>
</body>
</html>
[root@localhost ~]#

也可以通過(guò)docker inspect 容器名來(lái)查看容器的詳細(xì)信息和ip

通過(guò)容器ip進(jìn)行訪問(wèn):

?
1
2
3
[root@localhost ~]# docker inspect static_test
其他信息省略
"ipaddress": "172.17.0.5",
?
1
2
3
4
5
6
7
8
9
[root@localhost ~]# curl http://172.17.0.5/index.html
<html>
<body>
<h1>
  this is the first docker static file
</h1>
</body>
</html>
[root@localhost ~]#

當(dāng)我們使用docker stop 容器名停止這個(gè)容器后,再使用docker start 容器名啟動(dòng)容器后,里面的nginx并沒(méi)有啟動(dòng)。那么我們使用docker exec 容器名 nginx來(lái)啟動(dòng):

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
[root@localhost ~]# docker stop static_test
static_test
[root@localhost ~]# docker ps
container id  image       command     created    status    ports     names
b4f32bbe4a34  hub.c.163.com/library/ubuntu "/bin/bash"    41 hours ago  up 41 hours         loving_brattain
d75a2d8c7822  xingguo/df_test1    "nginx -g 'daemon off" 2 days ago   up 2 days   0.0.0.0:32770->80/tcp df_nginx_web
959c0fc5d903  xingguo/commit_test1   "nginx -g 'daemon off" 2 days ago   up 2 days   0.0.0.0:32769->80/tcp nginx_test
[root@localhost ~]# docker start static_test
static_test
[root@localhost ~]# docker ps
container id  image       command     created    status    ports     names
25fcbf6e953d  hub.c.163.com/library/ubuntu "/bin/bash"    29 minutes ago  up 2 seconds  0.0.0.0:32773->80/tcp static_test
b4f32bbe4a34  hub.c.163.com/library/ubuntu "/bin/bash"    41 hours ago  up 41 hours         loving_brattain
d75a2d8c7822  xingguo/df_test1    "nginx -g 'daemon off" 2 days ago   up 2 days   0.0.0.0:32770->80/tcp df_nginx_web
959c0fc5d903  xingguo/commit_test1   "nginx -g 'daemon off" 2 days ago   up 2 days   0.0.0.0:32769->80/tcp nginx_test
[root@localhost ~]# docker top static_test
uid     pid     ppid    c     stime    tty     time    cmd
root    4719    4702    0     13:17    pts/2    00:00:00   /bin/bash
[root@localhost ~]# docker exec static_test nginx
[root@localhost ~]# docker top static_test
uid     pid     ppid    c     stime    tty     time    cmd
root    4719    4702    0     13:17    pts/2    00:00:00   /bin/bash
root    4800    1     0     13:18    ?     00:00:00   nginx: master process nginx
amandab+   4801    4800    0     13:18    ?     00:00:00   nginx: worker process
amandab+   4802    4800    0     13:18    ?     00:00:00   nginx: worker process
amandab+   4803    4800    0     13:18    ?     00:00:00   nginx: worker process
amandab+   4804    4800    0     13:18    ?     00:00:00   nginx: worker process
amandab+   4805    4800    0     13:18    ?     00:00:00   nginx: worker process
amandab+   4806    4800    0     13:18    ?     00:00:00   nginx: worker process
amandab+   4807    4800    0     13:18    ?     00:00:00   nginx: worker process
amandab+   4808    4800    0     13:18    ?     00:00:00   nginx: worker process
[root@localhost ~]#

總結(jié)

以上就是這篇文章的全部?jī)?nèi)容了,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作能帶來(lái)一定的幫助,如有疑問(wèn)大家可以留言交流,謝謝大家對(duì)服務(wù)器之家的支持。

原文鏈接:http://blog.csdn.net/u014231523/article/details/61916145

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 极品销魂一区二区三区 | 五月激情久久 | 黄视频免费在线 | 色视频在线播放 | 万圣街在线观看免费完整版 | 成人在线视频免费看 | 日韩一级片一区二区三区 | 大胆在线日本aⅴ免费视频 永久免费毛片 | 久久免费视频一区二区三区 | 国产呻吟 | 日本精品久久久一区二区三区 | 精品一区二区三区网站 | 九色免费视频 | 欧美高清第一页 | 久久福利电影网 | 国产视频在线免费观看 | 天天干免费视频 | 91网站免费观看 | 欧美人与zoxxxx另类9 | 久久男人天堂 | 欧美在线综合视频 | 久久精品人人做人人爽 | 国产精品一区网站 | 国产亚洲黑人性受xxxx精品 | 国产精品久久久久免费视频 | 九九精品免费 | 激情综合视频 | 欧美日本色 | 欧洲黄色一级视频 | 一区二区久久精品66国产精品 | 91精品国产综合久久久欧美 | 欧美高清第一页 | 国产成人精品二区 | 久久久久北条麻妃免费看 | 国产草草视频 | 亚洲欧美国产精品va在线观看 | 亚洲成人精品一区二区 | 永久在线观看电影 | 精品一区二区免费 | 欧美综合成人 | 精品国产一区二区亚洲人成毛片 |