比如说我们在docker里面起了一个web服务器,我们想让外部进行访问,例如:
sudo docker run --name appleweb -d nginx
这样我们就起了一个web服务器,现在我们在这个服务器的里面是能够访问的
[vagrant@docker-node1 flask-redis]$ curl http://172.17.0.2
<!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>
但是我们是跟外部进行服务的,我们就来看一下如何把nginx的80的端口映射到本地。其实方法不难,我们先把之前的appleweb删掉
[vagrant@docker-node1 flask-redis]$ docker stop appleweb
appleweb
[vagrant@docker-node1 flask-redis]$ docker rm appleweb
appleweb
下面我们在来建一个新的
[vagrant@docker-node1 flask-redis]$ sudo docker run --name appleweb -d -p 80:80 nginx
940fa05a86f60a17f34663090776364c6c7278c99d81d44f06e465cd39c889c0
我们再次访问,127.0.0.1,发现成功了。
网友评论