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