docker 安装 nginx

1、查找nginx
[root@localhost data1]#  docker search nginx

在这里插入图片描述

2、下载nginx
[root@localhost data1]# docker pull nginx

在这里插入图片描述

3、以终端的⽅式打开镜像容器
[root@localhost data1]# docker run -it nginx /bin/bash
  • -it 是 -i 与 -t两个参数合并写法,-i -t 标志着为我们指定的容器创建了TTY并捕捉了STDIN
  • /bin/bash 指定了执⾏命令的shell
4、查看内容并拷贝

拷贝nginx.conf配置内容

root@fa29e726b5cb:/# cat /etc/nginx/nginx.conf 

在这里插入图片描述

拷贝default.conf配置⽂件内容

cat /etc/nginx/conf.d/default.conf

在这里插入图片描述
拷贝后退出(exit)

5、在宿主机中创建挂载源⽂件和⽂件夹
[root@localhost data1]# mkdir -p /data1/nginx/conf.d
[root@localhost data1]# mkdir -p /data1/nginx/html
[root@localhost data1]# mkdir -p /data1/nginx/logs

在这里插入图片描述

6、创建⼀个nginx.conf配置⽂件

在创建的nginx⽂件夹⾥⾯创建⼀个nginx.conf配置⽂件 :

[root@localhost nginx]# vi nginx.conf

把之前从nginx.conf中拷⻉的内容粘贴到其中保存
在这里插入图片描述

7、创建⼀个default.conf⽂件

在conf.d⾥⾯创建⼀个default.conf⽂件

[root@localhost nginx]# cd conf.d
[root@localhost conf.d]# vi default.conf

把之前从default.conf中拷⻉的内容粘贴到其中保存
在这里插入图片描述

8、创建容器
[root@localhost conf.d]# docker run -d --name nginx -p 80:80 -v /data1/nginx/nginx.conf:/etc/nginx/nginx.conf -v /data1/nginx/logs:/var/log/nginx -v /data1/nginx/html/dist:/usr/share/nginx/html -v /data1/nginx/conf.d:/etc/nginx/conf.d --privileged=true nginx

在这里插入图片描述

  • –privileged=true 容器内部对挂载的⽬录拥有读写等权限
9、解压前端dist压缩包

把前端dist压缩包解压到/data1/nginx/html⽬录下

解压rar文件需要安装rar对应软件

[root@localhost local]# wget https://www.rarlab.com/rar/rarlinux-x64-6.0.2.tar.gz
[root@localhost local]# tar -zxvf rarlinux-x64-6.0.2.tar.gz
[root@localhost local]# cd rar
[root@localhost rar]# make install

然后再次进行解压

[root@localhost html]# rar x dist.rar
10、重启nginx
[root@localhost html]# docker restart nginx
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值