ZhangZhihui's Blog  

In order to access the nginx from our workstation, we would need to expose the port 80 from within the nginx container to our workstation. 

Run the nginx container once more, but now, we would need to ensure we expose port 80 of our nginx container to our workstation. At the same, we can try to use the -name flag so that we can control the name of the running container. We can provide a shorter docker container name in order to make it easier to control the container.

zzh@ZZHPC:~$ docker run -p 80:80 -d --name=test nginx
f37c663dc7058d5c470bb8f0dee20f1da9cb0add6862d3c826abc8d7d6935ffe
zzh@ZZHPC:~$ docker ps -a
CONTAINER ID   IMAGE         COMMAND                  CREATED          STATUS                   PORTS                               NAMES
f37c663dc705   nginx         "/docker-entrypoint.…"   10 seconds ago   Up 9 seconds             0.0.0.0:80->80/tcp, :::80->80/tcp   test

 

Note that for the ports of our running container test, it exposes port 80 to our workstation via the following CIDR (Classless Inter-Domain Routing is an IP address allocation method that improves data routing efficiency on the internet. Every machine, server, and end-user device that connects to the internet has a unique number, called an IP address, associated with it.) combination 0.0.0.0—which accepts traffic from any source at port 80. If we are to run the curl command from our workstation, we will get the expected response of the welcome nginx page:

复制代码
zzh@ZZHPC:~$ curl localhost
<!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>
复制代码

With this, we can even add localhost to any browser on our workstation to view the nginx welcome page.

 

posted on   ZhangZhihuiAAA  阅读(21)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律
历史上的今天:
2022-09-22 Shell - touch an old file
 
点击右上角即可分享
微信分享提示