我正在尝试在 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 容器正在运行,但我无法使用
为什么我需要它?我正在尝试学习新东西,是的,它必须是 Azure VM。操作系统可能不同。
最佳答案
由于您要在虚拟机中打开端口 80,因此您应该使用 -p 80:80 来运行容器。
关于linux - Azure VM/Docker – 如何在 Azure VM 上将网站部署为 Docker 容器 (Debian),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73973995/