我正在尝试将我的服务作为 Docker 容器托管在 Azure VM 上。我已经在虚拟机上成功运行了服务(屏幕截图 1)并打开了必要的端口(屏幕截图 2),我已经测试了服务正在运行并且可以从虚拟机内部访问(屏幕截图 3),但我仍然无法访问它们来自外部 - 既不通过 DNS 也不通过公共 IP :(
有人知道我错过了什么吗?
如果您无法使用
VM
访问从 Public IP
外部运行的服务,请务必检查 NSG
中允许的 端口:5000。
此外,从虚拟机外部检查公共 IP 的
port 5000
。如果您使用的是 公司 网络,请确保允许从公司网络访问相同的 IP
和 port 5000
。如需测试,请检查个人网络。
telnet <VM_PUBLIC_IP> 5000
我已使用以下配置在
VM
上部署了示例应用程序。
Dockerfile
FROM nginx:latest
COPY nginx.conf /etc/nginx/conf.d/default.conf
COPY index.html /usr/share/nginx/html/index.html
COPY graphql.html /usr/share/nginx/html/graphql.html
nginx.conf
server {
listen 80;
server_name localhost;
location / {
root /usr/share/nginx/html;
index index.html;
}
location /graphql {
alias /usr/share/nginx/html;
try_files /graphql.html =404;
}
}
确保将上述所有文件保存在同一目录中,包括
HTML
文件,并使用以下命令构建图像。
docker build -t venkatapp .
构建部署后,使用以下命令运行
Docker
容器。
docker run -d -p 5000:80 venkatapp
运行应用程序之前,请确保在 NSG
规则中允许
端口 5000
虚拟机内的本地主机结果
这是来自
VM
外部的
VM
公共 IP 的结果。