Docker安装Nginx

Docker安装Nginx

# 1、搜索镜像	推荐使用官网搜索
docker search nginx

[root@bogon home]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
# 2、拉取镜像
[root@bogon home]# docker pull nginx
Using default tag: latest
latest: Pulling from library/nginx
bf5952930446: Already exists 
ba755a256dfe: Pull complete 
c57dd87d0b93: Pull complete 
d7fbf29df889: Pull complete 
1f1070938ccd: Pull complete 
Digest: sha256:36b74457bccb56fbf8b05f79c85569501b721d4db813b684391d63e02287c0b2
Status: Downloaded newer image for nginx:latest
docker.io/library/nginx:latest
[root@bogon home]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
nginx               latest              08393e824c32        7 days ago          132MB
#3、启动镜像
# docker run -d --name mynginx -p 4433:80 镜像名 

	# --name mynginx	# 给我们启动的容器起个名字
	# -p 4433:80 		# 4433:80 主机端口与容器端口做映射
# 以交互模式启动	
[root@bogon ~]# docker run -it --name nginx02 -p 4433:80 nginx /bin/bash
root@76564a344b1b:/# 
# 以后台方式启动
[root@bogon home]# docker run -d --name mynginx -p 4433:80 nginx
b583310be4da6790918aab8234f260f9cbe9b3a06cc26d652c955a9aecff6751
# 开放4433端口
[root@bogon home]#  firewall-cmd --zone=public --add-port=4433/tcp --permanent
success
# 重启防火墙
[root@bogon home]# firewall-cmd --reload
success
# 查看当前所有tcp端口·
[root@bogon home]# netstat -ntlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1031/sshd           
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      1201/master         
tcp6       0      0 :::4433                 :::*                    LISTEN      60497/docker-proxy  
tcp6       0      0 :::22                   :::*                    LISTEN      1031/sshd           
tcp6       0      0 ::1:25                  :::*                    LISTEN      1201/master         
# 查看所有4433端口使用情况·
[root@bogon home]# netstat -ntulp |grep 4433
tcp6       0      0 :::4433                 :::*                    LISTEN      60497/docker-proxy 

[root@bogon home]# lsof -i:4433
COMMAND     PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
docker-pr 60497 root    4u  IPv6 286143      0t0  TCP *:vop (LISTEN)

# 访问Nginx 成功
[root@bogon home]# curl localhost:4433
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
    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>
[root@bogon home]# 

posted @ 2020-08-16 15:09  古城,老巷  阅读(180)  评论(0编辑  收藏  举报