Docker 安装 nginx

nginx常用于负载均衡、反向代理

# 1、搜索镜像,建议去docker hub 去搜索
docker search nginx

# 2、下载镜像
docker pull nginx

# 3、查看镜像
[root@qiaoyanjie ~]# docker images
REPOSITORY   TAG       IMAGE ID       CREATED       SIZE
nginx        latest    87a94228f133   2 weeks ago   133MB
centos       latest    5d0da3dc9764   5 weeks ago   231MB

# 4、启动镜像
-d    # 后台运行
--name    # 给容器命名
-p 宿主机端口:容器内部端口    
[root@qiaoyanjie ~]# docker run -d --name nginx01 -p 3344:80 nginx
089bc40ab20472cf0230343fba5074800ebdca2239f485a5ab8faa3ab68e9121
[root@qiaoyanjie ~]# docker ps
CONTAINER ID   IMAGE     COMMAND                  CREATED         STATUS         PORTS                  NAMES
089bc40ab204   nginx     "/docker-entrypoint.…"   6 seconds ago   Up 5 seconds   0.0.0.0:3344->80/tcp   nginx01
a30438b045f1   centos    "/bin/bash -c 'while…"   5 days ago      Up 5 days                             amazing_buck
82cc433f5fd8   centos    "/bin/bash"              6 days ago      Up 6 days                             vigilant_ptolemy
[root@qiaoyanjie ~]# curl localhost:3344    # 本机测试,成功
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
html { color-scheme: light dark; }
body { width: 35em; margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif; }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>

# 5、网页访问失败,需要阿里云开启安全组:实例--安全组--配置规则,开端3344端口后网页访问成功。

 

# 1、不开防火墙,可以访问;开了防火墙,不可访问,需要开通端口

# 2、开启端口
firewall-cmd --zone=public --add-port=3344/tcp --permanent

# 3、关闭端口
firewall-cmd --zone=public --remove-port=3344/tcp --permanent

# 4、重启防火墙
firewall-cmd --reload

# 5、查看开通端口
firewall-cmd --list-port

# 6、查询端口号15560是否开启
firewall-cmd --query-port=3344/tcp
yes/no

# 7、关闭防火墙
systemctl stop firewalld.service
systemctl disable firewalld.service
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值