[英]Cannot access a running docker container via public DNS on AWS EC2 instance
我想在AWS EC2实例上运行Angular Webapp。 我在Angular项目中创建了一个Dockerfile并将其部署到EC2实例。 Gitlab CI创建Angular项目和Docker映像。 它使用sudo docker run --name frontend -d -p 80:8080 registry.gitlab.com/.../frontend
执行容器。 如果现在我想通过公共URL访问webapp,则会发生以下错误:
此网页无法使用。 {ip} .eu-central-1.compute.amazonaws.com拒绝了该连接。
如何使我的Webapp公开?
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
来检查此确认是否正确,然后您将能够解决问题!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.