栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

docker—创建nginx容器

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

docker—创建nginx容器

创建nginx容器

需要同时提供配置文件和网页文件
实例:

[root@localhost ~]# docker run -it --name  html -v /var/www/html/:/usr/share/nginx/html busybox
/ # exit
[root@localhost ~]# docker ps -a
ConTAINER ID   IMAGE     COMMAND   CREATED         STATUS                     PORTS     NAMES
2712632a69b3   busybox   "sh"      9 seconds ago   Exited (0) 4 seconds ago             html
安装nginx并提供测试的配置文件
[root@localhost ~]# yum -y install nginx
[root@localhost ~]# mkdir /config
[root@localhost ~]# cp -r /etc/nginx/* /config/
[root@localhost ~]# ls /config/
conf.d                  koi-utf             scgi_params
default.d               koi-win             scgi_params.default
fastcgi.conf            mime.types          uwsgi_params
fastcgi.conf.default    mime.types.default  uwsgi_params.default
fastcgi_params          nginx.conf          win-utf
fastcgi_params.default  nginx.conf.default

基于容器html的容器卷挂载数据卷
[root@localhost ~]# docker run --name nginx_conf --volumes-from html   -v /config:/etc/nginx busybox
[root@localhost ~]# docker ps -a
ConTAINER ID   IMAGE     COMMAND   CREATED          STATUS                      PORTS     NAMES
4ff42fcb86c6   busybox   "sh"      33 seconds ago   Exited (0) 31 seconds ago             nginx_conf
2712632a69b3   busybox   "sh"      2 minutes ago    Exited (0) 2 minutes ago              html

基于容器nginx_conf的容器卷,创建nginx容器
[root@localhost ~]# docker run --name nginx -dit -p 80:80 --volumes-from nginx_conf nginx
Unable to find image 'nginx:latest' locally
latest: Pulling from library/nginx
e5ae68f74026: Pull complete 
21e0df283cd6: Pull complete 
ed835de16acd: Pull complete 
881ff011f1c9: Pull complete 
77700c52c969: Pull complete 
44be98c0fab6: Pull complete 
Digest: sha256:9522864dd661dcadfd9958f9e0de192a1fdda2c162a35668ab6ac42b465f0603
Status: Downloaded newer image for nginx:latest
ec7873759bf89814e2a253a5cc1b812090aa6db134f208101061a6828edd1d63
[root@localhost ~]# docker ps
ConTAINER ID   IMAGE     COMMAND                  CREATED          STATUS          PORTS                               NAMES
ec7873759bf8   nginx     "/docker-entrypoint.…"   16 seconds ago   Up 13 seconds   0.0.0.0:80->80/tcp, :::80->80/tcp   nginx

查看一下
[root@localhost ~]# docker exec -it nginx /bin/bash
root@ec7873759bf8:/# ls /etc/nginx/
conf.d                  koi-utf             scgi_params
default.d               koi-win             scgi_params.default
fastcgi.conf            mime.types          uwsgi_params
fastcgi.conf.default    mime.types.default  uwsgi_params.default
fastcgi_params          nginx.conf          win-utf
fastcgi_params.default  nginx.conf.default

编写网页文件,随便放一个网站
[root@localhost ~]# cd /var/www/html/
[root@localhost html]# ls
[root@localhost html]# ls
css  index.html  js
[root@localhost html]# cat index.html 


  
    
    别踩白块
    
    
  
  
    

score

0

去容器查看一下 root@ec7873759bf8:/# ls /usr/share/nginx/html/ css index.html js

效果图:

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/642217.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号