如何创建AngularJS应用的Docker容器? [英] How to create a Docker container of an AngularJS app?

查看:99
本文介绍了如何创建AngularJS应用的Docker容器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个具有以下结构的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
  • AngularJS and NodeJS app in Docker
  • Dockerize your Angular NodeJS application

推荐答案

首先,请遵循最佳实践指南来构建您的角度应用程序结构. 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.在应用程序的根文件夹(在index.html旁边)中创建一个Dockerfile

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆