linux - Azure VM/Docker – 如何在 Azure VM 上将网站部署为 Docker 容器 (Debian)

标签 linux azure docker dockerfile azure-virtual-machine

我正在尝试在 Azure 虚拟机端口 80 上将简单的网站部署为 Docker 容器。

程序:

1 – 创建虚拟机并打开端口 80:

az group create --name my-vm-rg --location germanywestcentral
az vm create --resource-group my-vm-rg --name linuxVM --image Debian --admin-username <admin_user> --admin-password <admin_password> --authentication-type password --public-ip-sku Standard --size Standard_B1ms --disable-integrity-monitoring
az vm open-port --resource-group my-vm-rg --name linuxVM --port 80

2 – 使用 Putty 连接到虚拟机并安装 Docker、nano、更新机器等。

3 – 使用<h1>Hello World</h1>创建新文件夹和简单的index.html

4 – 创建 Dockerfile

FROM nginx:1.17.1-alpine
LABEL maintainer="Name Surname <email>" description="Some random description"
COPY . /usr/share/nginx/html

5 – 构建 Dockerfile:

docker build -t docker-test-img .
docker image ls -a
docker run --name my-app -d -p 8080:80 docker-test-img
docker container ls -a

问题: Docker 容器正在运行,但我无法使用 :80 或 :8080 从本地计算机浏览器访问网站。我收到“无法访问此网站”错误。

为什么我需要它?我正在尝试学习新东西,是的,它必须是 Azure VM。操作系统可能不同。

最佳答案

由于您要在虚拟机中打开端口 80,因此您应该使用 -p 80:80 来运行容器。

关于linux - Azure VM/Docker – 如何在 Azure VM 上将网站部署为 Docker 容器 (Debian),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73973995/

相关文章:

c++ - 使用 Cern ROOT 绘图

azure - 尝试将 war 部署到 Azure 时出现问题

java - 插入数据, "MobileServiceTable must have a single id property defined"

linux - 在 Docker 容器中开发时如何管理权限?

linux - 当你执行一条你的 CPU 不支持的指令时会发生什么?

linux - 尝试分配内存映射 INDArray 时出现内存不足错误

php - CakePHP 1.3 : High CPU Usage

bash - Azure CLI 解析

mysql - 从 docker 容器连接到远程 MySQL 数据库

docker - VSTS构建管道如何共享docker任务的输出?