无法访问docker容器架设的服务器,需要怎样调试。

1、
首先建立基础的nginx服务器。

docker run -d -p 1234:80 nginx:latest 
docker ps

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
6afe2e74773a nginx:latest "nginx -g 'daemon ..." 6 seconds ago Up 5 seconds 0.0.0.0:1234->80/tcp goofy_goldstine


其中1234就是绑定的外部的端口号。
接着,执行

curl 127.0.0.1:1234

得到结果:

<!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是正常的。
2、接着执行挂载卷的命令

sudo docker run -d -p 80 --name website11 -v $PWD/website:/var/www/html/website jamtur01/nginx nginx

sudo docker ps后可以看到

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
46c490d5f8d4 jamtur01/nginx "nginx" 12 seconds ago Up 11 seconds 0.0.0.0:32773->80/tcp website11
于是执行

curl 127.0.0.1:32773

返回:

<html>
<head><title>403 Forbidden</title></head>
<body bgcolor="white">
<center><h1>403 Forbidden</h1></center>
<hr><center>nginx/1.4.6 (Ubuntu)</center>
</body>
</html>
这说明错了。错在哪里呢?
3、

执行

docker inspect --format='{{.Mounts}}' website11 

查看绑定的信息

[{bind /home/user/sample/website/website /var/www/html/website true }]
这时候,发现本地目录/home/user/sample/website/website不正确。
于是切换到正确的位置,重新执行docker run 的名称。
再次执行curl,成功。

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值