最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

 更新時間:2017年06月13日 11:16:57   作者:興國First  
這篇文章主要給大家介紹了在Docker容器中部署靜態(tài)網(wǎng)頁的方法教程,文中介紹的非常詳細(xì),對大家具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來一起看看吧。

前言

一般我們在訪問容器時需要通過容器的端口來訪問,那如何設(shè)置容器的端口映射呢?

我們通過以下命令來設(shè)置:

docker run -p ip:hostPort:containerPort [--name] [-i] [-t] 鏡像名 [COMMAND][ARG...]
  • ip:表示宿主機(jī)ip
  • hostPort:宿主機(jī)端口號
  • containerPort:容器端口號

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

containerPort,指定容器端口號,宿主機(jī)端口隨機(jī)生成

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

hostPort:containerPort映射主機(jī)端口和容器端口

[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ī)端口到容器端口

[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映射指定地址的指定端口到容器的指定端口

[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

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

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

      - 安裝nginx

      - 安裝文本編輯器vim

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

      - 運(yùn)行nginx

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

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

[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:

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)建一個簡單的html文件:

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)建的目錄:

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 

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

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)行情況,也可以通過dcoker port 鏡像名查看:

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端口。

通過curl訪問創(chuàng)建的index.html文件:

[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 ~]#

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

通過容器ip進(jìn)行訪問:

[root@localhost ~]# docker inspect static_test
其他信息省略
"IPAddress": "172.17.0.5",
[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 容器名停止這個容器后,再使用docker start 容器名啟動容器后,里面的nginx并沒有啟動。那么我們使用docker exec 容器名 nginx來啟動:

[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é)

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

相關(guān)文章

  • Docker?配置容器固定IP的方法

    Docker?配置容器固定IP的方法

    這篇文章主要介紹了Docker?配置容器固定IP,下面使用docker自帶的network實(shí)現(xiàn)固定ip分配,并且重啟不會消失,通過綁定步驟給大家介紹的非常詳細(xì),需要的朋友參考下吧
    2022-04-04
  • 解決Docker啟動Elasticsearch7.x報(bào)錯的問題

    解決Docker啟動Elasticsearch7.x報(bào)錯的問題

    這篇文章主要介紹了解決Docker啟動Elasticsearch7.x報(bào)錯的問題,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-11-11
  • Docker volume使用詳解及實(shí)例

    Docker volume使用詳解及實(shí)例

    這篇文章主要介紹了Docker volume使用詳解及實(shí)例的相關(guān)資料,并附簡單實(shí)例,幫助大家學(xué)習(xí)參考,需要的朋友可以看下
    2016-11-11
  • Ubuntu使用Docker部署Redis并實(shí)現(xiàn)遠(yuǎn)程訪問本地?cái)?shù)據(jù)庫全過程

    Ubuntu使用Docker部署Redis并實(shí)現(xiàn)遠(yuǎn)程訪問本地?cái)?shù)據(jù)庫全過程

    這篇文章主要給大家介紹了關(guān)于Ubuntu使用Docker部署Redis并實(shí)現(xiàn)遠(yuǎn)程訪問本地?cái)?shù)據(jù)庫的相關(guān)資料,Redis遠(yuǎn)程連接是指通過網(wǎng)絡(luò)連接到Redis服務(wù)器,從而可以在不同的機(jī)器問和操作Redis數(shù)據(jù)庫,需要的朋友可以參考下
    2024-03-03
  • 樹莓派安裝Docker的方法步驟

    樹莓派安裝Docker的方法步驟

    這篇文章主要介紹了樹莓派安裝Docker的方法步驟,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2019-01-01
  • 詳解Docker 下開發(fā) hyperf 完整使用示例

    詳解Docker 下開發(fā) hyperf 完整使用示例

    這篇文章主要介紹了詳解Docker 下開發(fā) hyperf 完整使用示例,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-01-01
  • 在 Docker 中查看日志的方法

    在 Docker 中查看日志的方法

    文章介紹了如何在Docker中查看容器的日志,包括使用dockerlogs命令的基本方法、實(shí)時查看日志、查看特定時間范圍內(nèi)的日志以及配置日志驅(qū)動程序,還提到了通過docker-compose查看多個服務(wù)的日志,并討論了日志輪換和集成日志聚合工具的高級技巧,感興趣的朋友一起看看吧
    2025-03-03
  • 關(guān)于docker容器部署redis步驟介紹

    關(guān)于docker容器部署redis步驟介紹

    大家好,本篇文章主要講的是關(guān)于docker容器部署redis步驟介紹,感興趣的同學(xué)趕快來看一看吧,對你有幫助的話記得收藏一下,方便下次瀏覽
    2021-11-11
  • docker鏡像如何啟動es/kibana

    docker鏡像如何啟動es/kibana

    這篇文章主要介紹了docker鏡像如何啟動es/kibana問題,具有很好的參考價(jià)值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2024-01-01
  • docker redis5.0 cluster集群搭建的實(shí)現(xiàn)

    docker redis5.0 cluster集群搭建的實(shí)現(xiàn)

    這篇文章主要介紹了docker redis5.0 cluster集群搭建的實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-02-02

最新評論

杨浦区| 和平县| 满洲里市| 泸州市| 曲麻莱县| 鄄城县| 谢通门县| 宁海县| 合山市| 玉门市| 徐闻县| 赤壁市| 大悟县| 南郑县| 康马县| 大英县| 曲麻莱县| 和龙市| 轮台县| 体育| 太湖县| 隆安县| 东阳市| 旅游| 阳曲县| 昌邑市| 沧州市| 金坛市| 台南市| 潼南县| 佳木斯市| 凤庆县| 兴仁县| 嘉定区| 东兰县| 兰溪市| 龙陵县| 铁力市| 保山市| 扬中市| 陆丰市|