docker部署Nginx

下载Nginx

 docker pull nginx
Using default tag: latest
latest: Pulling from library/nginx
f7ec5a41d630: Already exists
aa1efa14b3bf: Pull complete
b78b95af9b17: Pull complete
c7d6bca2b8dc: Pull complete
cf16cd8e71e0: Pull complete
0241c68333ef: Pull complete
Digest: sha256:75a55d33ecc73c2a242450a9f1cc858499d468f077ea942867e662c247b5e412
Status: Downloaded newer image for nginx:latest
docker.io/library/nginx:latest

运行

docker run -d --name nginx01 -p 8080:80 nginx
0a178ec21a52c08ea40832ae3e4b503dfc2b50e1707eb84e1e13c914f9a2d5cc
[root@VM-0-4-centos ~]# ^C
[root@VM-0-4-centos ~]# docker run -d --name nginx01 -p 8080:80 nginx
docker: Error response from daemon: Conflict. The container name "/nginx01" is already in use by container "0a178ec21a52c08ea40832ae3e4b503dfc2b50e1707eb84e1e13c914f9a2d5cc". You have to remove (or rename) that container to be able to reuse that name.
See 'docker run --help'.
[root@VM-0-4-centos ~]# curl localhost 8080
curl: (7) Failed connect to localhost:80; Connection refused
curl: (7) Failed to connect to 0.0.31.144: Invalid argument

-d:后台运行
–name:别名
-p端口映射
其中端口原理如下所示:外网要访问nginx,需要先通过阿里云,然后访问主机8080。而nginx在将80端口映射到主机8080就可以完成访问。

在这里插入图片描述
查看8080端口的运行状态

[root@VM-0-4-centos ~]# curl localhost:8080
<!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>

访问结果
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值