如何创建 AngularJS 应用程序的 Docker 容器? [英] How to create a Docker container of an AngularJS app?
问题描述
我有一个具有这种结构的 AngularJS 应用程序:
I have an AngularJS app that has this structure:
app/
----- controllers/
---------- mainController.js
---------- otherController.js
----- directives/
---------- mainDirective.js
---------- otherDirective.js
----- services/
---------- userService.js
---------- itemService.js
----- js/
---------- bootstrap.js
---------- jquery.js
----- app.js
views/
----- mainView.html
----- otherView.html
----- index.html
如何创建自己的映像并在容器上运行它?我尝试使用 Dockerfile 运行它但没有成功,而且我对 Docker 比较陌生,所以如果这很简单,我深表歉意.我只想在 http 服务器上运行它(也许使用 nginx?)
How do I go about creating my own image out of this and running it on a container? I've tried running it with no success with a Dockerfile and I'm relatively new to Docker so apologies if this is simple. I just want to run it on a http server (using nginx perhaps?)
我已经尝试过这些寻求帮助,但没有成功:
I've tried these for help, to no success:
- https://www.quora.com/Can-I-have-an-Angular-app-on-Docker-container
- Docker 中的 AngularJS 和 NodeJS 应用
- Docker 化您的 Angular NodeJS 应用程序
推荐答案
首先,按照这个最佳实践指南 来构建您的 Angular 应用程序结构.index.html 应该放在根文件夹中.如果不存在,我不确定以下步骤是否有效.
First of all, follow this best practice guide to build your angular app structure. The index.html should be placed in the root folder. I am not sure if the following steps will work, if it's not there.
要使用 nginx,您可以按照以下小教程进行操作:使用 nginx 的 Dockerized Angular 应用
To use a nginx, you can follow this small tutorial: Dockerized Angular app with nginx
1.在应用的根文件夹中创建一个 Dockerfile(在您的 index.html 旁边)
1.Create a Dockerfile in the root folder of your app (next to your index.html)
FROM nginx
COPY ./ /usr/share/nginx/html
EXPOSE 80
2.在你的Dockerfile文件夹中运行docker build -t my-angular-app.
.
2.Run docker build -t my-angular-app .
in the folder of your Dockerfile.
3.docker run -p 80:80 -d my-angular-app
然后你就可以访问你的应用了 http://localhost
3.docker run -p 80:80 -d my-angular-app
and then you can access your app http://localhost
这篇关于如何创建 AngularJS 应用程序的 Docker 容器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!