Angular 无法通过AWS EC2实例上的公共DNS访问正在运行的docker容器
我想在AWS EC2实例上运行Angular Webapp。我在Angular项目中创建了一个Dockerfile,并将其部署到EC2实例中。Gitlab CI创建角度项目和Docker图像。它使用Angular 无法通过AWS EC2实例上的公共DNS访问正在运行的docker容器,angular,amazon-web-services,docker,amazon-ec2,Angular,Amazon Web Services,Docker,Amazon Ec2,我想在AWS EC2实例上运行Angular Webapp。我在Angular项目中创建了一个Dockerfile,并将其部署到EC2实例中。Gitlab CI创建角度项目和Docker图像。它使用sudocker run--name frontend-d-p80:8080 registry.gitlab.com/../frontend执行容器。如果我现在想通过公共URL访问webapp,则会出现以下错误: 此网页不可用。{ip}.eu-central-1.compute.amazonaws.c
sudocker run--name frontend-d-p80:8080 registry.gitlab.com/../frontend
执行容器。如果我现在想通过公共URL访问webapp,则会出现以下错误:
此网页不可用。{ip}.eu-central-1.compute.amazonaws.com已拒绝连接
如何公开我的Web应用程序
Dockerfile
FROM node:latest as node
WORKDIR /app
COPY . .
RUN npm install
RUN ng build
FROM nginx:alpine
COPY --from=node /app/dist/frontend /usr/share/nginx/html
EXPOSE 8080
Tsconfig.json
{
"compileOnSave": false,
"compilerOptions": {
"baseUrl": "./",
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"module": "es2015",
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"importHelpers": true,
"target": "es5",
"typeRoots": [
"node_modules/@types"
],
"lib": [
"es2018",
"dom"
]
}
}
gitlab-ci.yml
production-build:
stage: angular-build
image: trion/ng-cli
before_script:
- npm ci
script:
- ng build
artifacts:
paths:
- dist/
docker-build:
stage: docker-build
script:
- docker build -t registry.gitlab.com/.../frontend .
- docker login -u gitlab-ci-token -p $CI_BUILD_TOKEN registry.gitlab.com
- docker push registry.gitlab.com/.../frontend
EC2入站规则
更新
这可能与您的输出目录有关,因此当您将
/app/dist/frontend
复制到/usr/share/nginx/html
时,html文件夹中没有index.html,而是另一个文件夹。尝试进入容器并运行ls/usr/share/nginx/html
检查此错误信息是否正确,然后您就可以解决问题了 点击curl localhost:80
时,它是否返回网页?否有错误:curl:(52)服务器的空回复谢谢,我检查了docker目录,它包含正确的索引文件。我已经更新了我的问题。所以,作为我最后的猜测,我会检查nginx配置文件以查看它所服务的目录。。。如果你使用的是Ubuntu,它可能是/var/www/html