本机怎么访问docker容器内的网站呢,已将容器的80端口映射到了本机的80端口

比如我在容器内部署了 laravel.test 我在本机怎么访问到这个laravel.test啊 现在localhost是可以的

这是本机 ping localhost

C:\Users\Administrator>ping localhost

正在 Ping DESKTOP-ID2TSG [::1] 具有 32 字节的数据:
来自 ::1 的回复: 时间<1ms
来自 ::1 的回复: 时间<1ms
来自 ::1 的回复: 时间<1ms
来自 ::1 的回复: 时间<1ms

::1 的 Ping 统计信息:
    数据包: 已发送 = 4,已接收 = 4,丢失 = 0 (0% 丢失)往返行程的估计时间(以毫秒为单位):
    最短 = 0ms,最长 = 0ms,平均 = 0ms

本机怎么访问docker容器内的网站呢,已将容器的80端口映射到了本机的80端口

我能访问 127.0.0.1的东西 localhost 也可以

本机怎么访问docker容器内的网站呢,已将容器的80端口映射到了本机的80端口

但是ping localhost 的时候跟ping 其他我自定义域名的时候不一样 下面是ping测试域名的
C:\Users\Administrator>ping erp.test

正在 Ping erp.test [127.0.0.1] 具有 32 字节的数据:
来自 127.0.0.1 的回复: 字节=32 时间<1ms TTL=128
来自 127.0.0.1 的回复: 字节=32 时间<1ms TTL=128
来自 127.0.0.1 的回复: 字节=32 时间<1ms TTL=128
来自 127.0.0.1 的回复: 字节=32 时间<1ms TTL=128

127.0.0.1 的 Ping 统计信息:
    数据包: 已发送 = 4,已接收 = 4,丢失 = 0 (0% 丢失)往返行程的估计时间(以毫秒为单位):
    最短 = 0ms,最长 = 0ms,平均 = 0ms

这是我本机的hosts文件内容

# Copyright (c) 1993-2009 Microsoft Corp.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
#
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
#
# For example:
#
#      102.54.94.97     rhino.acme.com          # source server
#       38.25.63.10     x.acme.com              # x client host

# localhost name resolution is handled within DNS itself.
#    127.0.0.1       localhost
#    ::1             localhost
127.0.0.1 erp.test
127.0.0.1 localhost
#192.168.10.10  health.test
#127.0.0.1 aaaa.test
# Added by Docker Desktop
192.168.1.102 host.docker.internal
192.168.1.102 gateway.docker.internal
# To allow the same kube context to work on the host and the container:
127.0.0.1 kubernetes.docker.internal
# End of section

容器内部的nginx配置
server
{
listen 80;
server_name erp.test;
index index.php index.html index.htm default.php default.htm default.html;
root /www/wwwroot/erp;

#SSL-START SSL相关配置,请勿删除或修改下一行带注释的404规则
#error_page 404/404.html;
#SSL-END

#ERROR-PAGE-START  错误页配置,可以注释、删除或修改
#error_page 404 /404.html;
#error_page 502 /502.html;
#ERROR-PAGE-END

#PHP-INFO-START  PHP引用配置,可以注释或修改
include enable-php-81.conf;
#PHP-INFO-END

#REWRITE-START URL重写规则引用,修改后将导致面板设置的伪静态规则失效
include /www/server/panel/vhost/rewrite/erp.test.conf;
#REWRITE-END

#禁止访问的文件或目录
location ~ ^/(\.user.ini|\.htaccess|\.git|\.env|\.svn|\.project|LICENSE|README.md)
{
    return 404;
}

#一键申请SSL证书验证目录相关设置
location ~ \.well-known{
    allow all;
}

#禁止在证书验证目录放入敏感文件
if ( $uri ~ "^/\.well-known/.*\.(php|jsp|py|js|css|lua|ts|go|zip|tar\.gz|rar|7z|sql|bak)$" ) {
    return 403;
}

location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
    expires      30d;
    error_log /dev/null;
    access_log /dev/null;
}

location ~ .*\.(js|css)?$
{
    expires      12h;
    error_log /dev/null;
    access_log /dev/null;
}
access_log  /www/wwwlogs/erp.test.log;
error_log  /www/wwwlogs/erp.test.error.log;

}

《L02 从零构建论坛系统》
以构建论坛项目 LaraBBS 为线索,展开对 Laravel 框架的全面学习。应用程序架构思路贴近 Laravel 框架的设计哲学。
《L01 基础入门》
我们将带你从零开发一个项目并部署到线上,本课程教授 Web 开发中专业、实用的技能,如 Git 工作流、Laravel Mix 前端工作流等。
最佳答案

docker 在本机?映射 80 端口了,按道理在本机电脑hosts 添加就行啊 127.0.0.1 laravel.test

2年前 评论
周小云 (楼主) 2年前
php_yt (作者) 2年前
周小云 (楼主) 2年前
周小云 (楼主) 2年前
php_yt (作者) 2年前
周小云 (楼主) 2年前
php_yt (作者) 2年前
周小云 (楼主) 2年前
周小云 (楼主) 2年前
周小云 (楼主) 2年前
讨论数量: 21

改 host 文件?

2年前 评论
周小云 (楼主) 2年前

修改 host 呢是最简单的做法,但是每次有新的项目都要手动加一下!

当然你也可以在 Docker 中部署一个 CoreDNS 服务,具体参考《使用 CoreDNS 搭建本地域名服务》

2年前 评论
周小云 (楼主) 2年前
周小云 (楼主) 2年前

如果你只是想要单纯的 用 laravel.test 访问的话,你可以这样;先把本地hosts文件添加 laravel.test docker容器ip:端口号;docker 容器中不需要做任何修改;

2年前 评论

注意 docker的ip是动态(如果你没有做静态处理的话); 如果你可以使用127.0.0.1:端口号访问到容器部署的项目,那你就在宿主机的host 配置 laravel.test 127.0.0.1:端口号

2年前 评论
周小云 (楼主) 2年前
周小云 (楼主) 2年前

docker 在本机?映射 80 端口了,按道理在本机电脑hosts 添加就行啊 127.0.0.1 laravel.test

2年前 评论
周小云 (楼主) 2年前
php_yt (作者) 2年前
周小云 (楼主) 2年前
周小云 (楼主) 2年前
php_yt (作者) 2年前
周小云 (楼主) 2年前
php_yt (作者) 2年前
周小云 (楼主) 2年前
周小云 (楼主) 2年前
周小云 (楼主) 2年前

ping没有用啊,改hosts 文件 127.0.0.1 laravel.test

2年前 评论
周小云 (楼主) 2年前
Dash007 (作者) 2年前

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!