我想在本地浏览器中托管我的Angular 应用程序。
这是我的docker文件配置:-
FROM node:10.13.0-alpine as builder
WORKDIR /usr/src/app
COPY package.json package-lock.json ./
RUN npm cache clean --force
COPY . ./
RUN npm install
RUN npm run build --prod
FROM nginx:alpine
COPY --from=builder /usr/src/app /usr/share/nginx/html
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
现在我尝试构建映像并在localhost:8080上运行它:-
NET和Angular\QuizQuestion\Fornted〉文档运行--名称问题1-d -p 8080:80问题005 fd 1a 397 f38 c54675 b24 be 1a 502 b32 edadc 5 f653 bda 8be 07 b62 c4448 b3 a7
我只能看到nginx的欢迎页面。
如果我浏览了
但它是与npm启动:-
我有点困惑我错过了什么。
我做这个练习后,我得到了建议,从先生戴夫迷宫x1c4d 1x
它显示了很多不需要的folder.So,我在我的docker文件中更改以下内容:-
FROM nginx:alpine
COPY --from=builder /usr/src/app/dist /usr/share/nginx/html
现在的文件夹结构如下:-
但是它不起作用,我没有得到想要的结果。
Docker运行命令:-
docker run --name quizquestion4 -d -p 4000:80 quizequstion
22 ac 476 a121 d221808415 a2 f59 c6 f511 e765 fd 7 d5325 c 03 b 9 ff 320905 e0 cd 02 c.是的,它在没有对接器的情况下工作正常。
我注意到的事情:-
如果我改变了app-routing.模块,比如:-′
{ path: '', component: QuizComponent},
{ path: 'quiz', component: QuizComponent},
{ path: 'question', component: QuestionComponent },
{ path: 'question/:quizId', component: QuestionComponent },
{ path: 'register', component: RegisterComponent },
{ path: 'login', component: LoginComponent},
{ path: 'customer-list', component: CustomerListComponent},
然后我创建新的Docker映像并重建它。我在http://localhost:4001上的端口上运行它:-我可以看到测验表单
指令集
但是路由http://localhost:4001/quiz不起作用。它给我404未找到。
是,在本地,没有dockerimage,它可以正常工作:-
因此,对于Angular 路由,我需要做任何补充的事情,使码头形象。
我把它标记为angular js。
我想我在码头大楼里漏掉了什么。
有什么建议吗?谢谢
2条答案
按热度按时间bwitn5fc1#
对于Docker容器,如果您未指定任何主机,则它将在Docker容器IP上启动。
你可以得到这个(下面),并获得IP地址(很多其他好的信息也有!)
docker inspect <container id>
如果您只需要IP地址:
https://docs.docker.com/config/containers/container-networking/
默认情况下,会为container连接到的每个Docker网络分配一个IP地址。IP地址是从分配给网络的池中分配的,因此Docker守护程序有效地充当每个container的DHCP服务器。每个网络还具有默认子网掩码和网关。
nzk0hqpo2#
最后我找到了解决办法:-
因此,我改变了dockerfile的内容:-
我们还需要在项目文件夹中创建Nginx配置文件。
就像这样:
配置文件的代码:-
请参阅说明:-https://javascript.plainenglish.io/angular-10-on-docker-to-production-61ee6e84006
感谢所有贡献者为这个职位