AngularJS的可重复使用的码头图像 [英] Reusable docker image for AngularJS

查看:149
本文介绍了AngularJS的可重复使用的码头图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个AngularJS应用程序。我们为它编写了一个docker文件,因此它可以在每个系统上重用。 dockerfile不是一个最佳实践,它可能是一些奇怪的建立(构建和托管在同一个文件)的一些,但它只是创建为在每个开发人员的每台PC上本地运行我们的angularjs应用程序。

  Dockerfile:
FROM nginx:1.10

...安装nodejs-legacy + npm
$的步骤b $ b RUN npm install -g gulp
RUN npm install
运行gulp build

..步骤移动dist文件夹

我们使用 docker build -t myapp来构建我们的图像:最新的。
每个开发人员能够运行我们的应用程序与 docker运行-d -p 80:80 myapp:最新的



但现在我们'重新开发其他后端所以我们有一个后端的DEV,一个在UAT的后端...
所以有不同的URLS,我们需要使用在 /config/xx.json

  {
...
service_base:https://backend.test.xxx /,
...
}

我们不想每次更改该URL,重建图像并启动它。我们也不想声明一些可以在那里使用的URLS(dev,uat,prod,..)。我们要执行我们的 gulp构建进程与环境变量而不是硬编码的URL。



所以我们可以开始我们的容器如下:

  docker run -d -p 80:80 --env URL = https:// mybackendurl。 com app:latest 

有人有这样的问题的经验吗?所以我们需要在我们的json中创建一个env变量并构建它,并在以后添加URL。

解决方案

编辑:更好的选择是使用build args



而不是在docker run命令中传递URL,可以使用docker build args。在Docker构建期间,建立相关的命令最好是比Docker运行。



在您的Docker文件中,

  ARG URL 

然后运行

  Docker build --build-arg URL =< my-url> 。 

看到这个 stackoverflow问题详细信息


We have an AngularJS application. We wrote a dockerfile for it so it's reusable on every system. The dockerfile isn't a best practice and it's maybe some weird build up (build and hosting in same file) for some but it's just created to run our angularjs app locally on each PC of every developer.

Dockerfile:
FROM nginx:1.10

... Steps to install nodejs-legacy + npm

RUN npm install -g gulp
RUN npm install
RUN gulp build  

.. steps to move dist folder

We build our image with docker build -t myapp:latest . Every developer is able to run our app with docker run -d -p 80:80 myapp:latest

But now we're developing other backends. So we have a backend in DEV, a backend in UAT, ... So there are different URLS which we need to use in /config/xx.json

{
  ...
  "service_base": "https://backend.test.xxx/",
  ...
}

We don't want to change that URL every time, rebuild the image and start it. We also don't want to declare some URLS (dev, uat, prod, ..) which can be used there. We want to perform our gulp build process with an environment variable instead of a hardcoded URL.

So we we can start our container like this:

docker run -d -p 80:80 --env URL=https://mybackendurl.com app:latest

Is there someone who has experience with this kind of issues? So we'll need an env variable in our json and building it and add the URL later on if that's possible.

解决方案

EDIT : Better option is to use build args

Instead of passing URL at docker run command, you can use docker build args. It is better to have build related commands to be executed during docker build than docker run.

In your Dockerfile,

ARG URL 

And then run

docker build --build-arg URL=<my-url> .

See this stackoverflow question for details

这篇关于AngularJS的可重复使用的码头图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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