简体   繁体   English

在 docker 容器上运行 Angular 应用程序时出现“Cannot GET /”错误

[英]"Cannot GET /" error when running angular application on docker container

I'm trying to run a Angular App on docker, but when I try to access some page, I get this error .我正在尝试在 docker 上运行 Angular 应用程序,但是当我尝试访问某个页面时,我收到了这个错误

I've tried to change the aot to false at angular.json , but it didn't work.我试图在angular.jsonaot更改为 false ,但它没有用。

Here is my Dockerfile:这是我的 Dockerfile:

WORKDIR /usr/src/app
COPY package*.json ./
RUN npm install -g @angular/cli
RUN npm install
COPY . ./
RUN npm run build
EXPOSE 8080
CMD [ "node", "server.js" ]

and here is my package.json:这是我的 package.json:

{
    "name": "app-name",
    "version": "0.0.2",
    "scripts": {
        "ng": "ng",
        "start": "ng serve --host 0.0.0.0",
        "build": "ng build",
        "test": "ng test",
        "lint": "ng lint",
        "e2e": "ng e2e",
        "update": "ncu -u -x firebase,@angular/fire"
    },
    "private": true,
    "dependencies": {
        "@angular/animations": "^14.0.0",
        "@angular/cdk": "~14.0.0",
        "@angular/common": "~14.0.0",
        "@angular/compiler": "~14.0.0",
        "@angular/core": "~14.0.0",
        "@angular/fire": "^7.3.0",
        "@angular/flex-layout": "^13.0.0-beta.38",
        "@angular/forms": "~14.0.0",
        "@angular/material": "^14.0.0",
        "@angular/platform-browser": "~14.0.0",
        "@angular/platform-browser-dynamic": "~14.0.0",
        "@angular/pwa": "^14.0.0",
        "@angular/router": "~14.0.0",
        "@angular/service-worker": "~14.0.0",
        "@fortawesome/angular-fontawesome": "^0.11.0",
        "@fortawesome/fontawesome-svg-core": "^6.1.1",
        "@fortawesome/free-solid-svg-icons": "^6.1.1",
        "@ngx-translate/core": "^14.0.0",
        "@ngx-translate/http-loader": "^7.0.0",
        "bootstrap": "^5.1.3",
        "crypto-js": "^4.1.1",
        "file-saver": "^2.0.5",
        "firebase": "^8.10.0",
        "jwt-decode": "^3.1.2",
        "material-design-icons": "^3.0.1",
        "ng2-pdf-viewer": "^9.0.0",
        "ngx-mask": "^14.0.0",
        "ngx-toastr": "^14.3.0",
        "rxjs": "^7.5.5",
        "tslib": "^2.4.0",
        "zone.js": "^0.11.5"
    },
    "devDependencies": {
        "@angular-devkit/build-angular": "^14.0.0",
        "@angular/cli": "~14.0.0",
        "@angular/compiler-cli": "~14.0.0",
        "@angular/language-service": "~14.0.0",
        "@types/crypto-js": "^4.1.1",
        "@types/jasmine": "~4.0.3",
        "@types/jasminewd2": "~2.0.10",
        "@types/node": "~17.0.40",
        "codelyzer": "^6.0.2",
        "jasmine-core": "~4.1.1",
        "jasmine-spec-reporter": "~7.0.0",
        "karma": "~6.3.20",
        "karma-chrome-launcher": "~3.1.1",
        "karma-coverage-istanbul-reporter": "~3.0.3",
        "karma-jasmine": "~5.0.1",
        "karma-jasmine-html-reporter": "^2.0.0",
        "protractor": "~7.0.0",
        "ts-node": "~10.8.1",
        "tslint": "^6.1.3",
        "typescript": "^4.7.3"
    }
}

If anyone has already faced this error and knows how to solve it, I would greatly appreciate it, thanks.如果有人已经遇到此错误并且知道如何解决它,我将不胜感激,谢谢。

I solved the problem using the useHash: true on my app-routing.module.ts .我在app-routing.module.ts上使用useHash: true解决了这个问题。

Now I got link like something.com/#/someParameter现在我得到了类似 something.com/#/someParameter 的链接

@NgModule({
    imports: [RouterModule.forRoot(routes, {relativeLinkResolution: 'legacy', useHash: true})],
    exports: [RouterModule]
})
export class AppRoutingModule {
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在 Docker 容器内运行 Sails.js 应用程序时出现“无法加载 gRPC 二进制模块”错误 - "Failed to load gRPC binary module" error when running a Sails.js application inside a Docker container 当使用其他用户运行容器时,Docker无法在构建中运行 - Docker cannot run on build when running container with a different user 在 Docker 容器中访问 Angular 应用程序 - Access Angular application in a Docker container 使用Docker Compose运行节点容器时出错 - Error when running node container using docker compose HTTP 在 Docker 容器中运行时,Nodejs 中的解析错误 - HTTP Parse Error in Nodejs when running in a Docker Container Docker容器在运行时抛出错误 - Docker container throwing error on running it 启动 Docker 容器时运行 npm 脚本时出错 - Error running npm Script when starting Docker Container 当我尝试使用 docker-compose 为 nodejs 和 mysql 应用程序运行 docker 容器时出现端口使用错误 - I get port in use error when I try to run the docker container for the nodejs and mysql application using the docker-compose 检查 React 应用程序是否在 Docker 容器中运行 - Check whether React application is running in a Docker container Docker 节点服务在运行 npm 时返回 ECONNRESET 网络错误安装在 docker 容器中 - Docker node service return ECONNRESET network error when running npm install in docker container
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM