如何使用nginx + docker将AngularJS应用部署到弹性豆茎上?

时间:2022-08-25 09:19:25

So I'm in the process of deploying an AngularJS app to an AWS Elastic Beanstalk instance.

因此,我正在将AngularJS应用程序部署到AWS弹性Beanstalk实例中。

I've successfully configured the build requirements, which involves uploading a Dockerrun.aws.json file that's configured to access an S3 storage bucket which in turn contains the .dockercfg file, used for accessing my private Docker repo.

我已经成功地配置了构建需求,其中包括上传docker .aws。配置为访问S3存储桶的json文件,而S3存储桶又包含.dockercfg文件,用于访问我的私有Docker repo。

Everything builds successfully, and nginx runs. I get the default "Welcome to nginx on Debian!" message.

所有的东西都成功构建,nginx运行。我得到默认的“欢迎来到nginx的Debian!”消息。

So the only thing I'm having an issue with is now pointing the build of my AngularJS app to the active/home page (where the "Welcome.." screen appears.)

所以我现在唯一的问题是把我的AngularJS应用程序的构建指向活动/主页(欢迎…)

All of the app's contents are stored inside /build, from the root directory of the project, which is where my Dockerfile is contained.

应用程序的所有内容都存储在/build中,来自项目的根目录,我的Dockerfile就位于这个目录中。

From what I've gathered so far I think I need to go along the lines of:

从我目前收集到的信息来看,我认为我需要遵循以下几点:

FROM nginx
COPY /build/ /usr/share/nginx/html

Placed inside the Dockerfile, however those particular commands don't work.

放置在Dockerfile中,但是这些特定的命令不能工作。

I'm sure it's relatively trivial achieving what I'm hoping to, but having scoured various articles and documentations I can't find a simple answer. Any help much appreciated.

我确信实现我所希望的目标是相对微不足道的,但是在搜索了各种文章和文档之后,我找不到一个简单的答案。感谢任何帮助。

2 个解决方案

#1


2  

So I actually found the proper solution to this, in typical fashion, a few minutes after I'd written this question.

所以我找到了正确的解决方法,以典型的方式,写完这个问题几分钟后。

Kapott's answer is also along the right lines, however it's not quite there, so for good measure here's the answer:

卡波特的答案也是正确的,但它并不完全正确,所以为了更好的衡量,以下是答案:

COPY <directory_containing_app_index> /var/www/html/

The public html is stored inside the nginx directory /var/www/html/. I copied /usr/share/nginx/html/ from the nginx docker page, although I didn't expect that to be correct, it seemed from the explanation that was the way to do it.

公共html存储在nginx目录/var/www/html/中。我从nginx docker页面上复制了/usr/share/nginx/html/,尽管我没有预料到这是正确的,但从解释上看,这似乎是一种方法。

#2


1  

You're almost there. Try omitting the first slash in the Dockerfile's copy command, so it takes the path relative to the Dockerfile:

你差不多了。尝试删除Dockerfile复制命令中的第一个斜杠,因此它采用与Dockerfile相关的路径:

COPY build /usr/share/nginx/html/

构建/usr/share/nginx/html/副本

#1


2  

So I actually found the proper solution to this, in typical fashion, a few minutes after I'd written this question.

所以我找到了正确的解决方法,以典型的方式,写完这个问题几分钟后。

Kapott's answer is also along the right lines, however it's not quite there, so for good measure here's the answer:

卡波特的答案也是正确的,但它并不完全正确,所以为了更好的衡量,以下是答案:

COPY <directory_containing_app_index> /var/www/html/

The public html is stored inside the nginx directory /var/www/html/. I copied /usr/share/nginx/html/ from the nginx docker page, although I didn't expect that to be correct, it seemed from the explanation that was the way to do it.

公共html存储在nginx目录/var/www/html/中。我从nginx docker页面上复制了/usr/share/nginx/html/,尽管我没有预料到这是正确的,但从解释上看,这似乎是一种方法。

#2


1  

You're almost there. Try omitting the first slash in the Dockerfile's copy command, so it takes the path relative to the Dockerfile:

你差不多了。尝试删除Dockerfile复制命令中的第一个斜杠,因此它采用与Dockerfile相关的路径:

COPY build /usr/share/nginx/html/

构建/usr/share/nginx/html/副本