Reusable docker image for AngularJS Reusable docker image for AngularJS json json

Reusable docker image for AngularJS


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


This was my 'solution'. I know it isn't the best docker approach but just for our developers it was a big help.

My dockerfile looks like this:

FROM nginx:1.10RUN apt-get update && \ apt-get install -y curlRUN sed -i "s/httpredir.debian.org/`curl -s -D - http://httpredir.debian.org/demo/debian/ | awk '/^Link:/ { print $2 }' | sed -e 's@<http://\(.*\)/debian/>;@\1@g'`/" /etc/apt/sources.listRUN \  apt-get clean && \  apt-get update && \  apt-get install -y nodejs-legacy && \  apt-get install -y npmWORKDIR /home/appCOPY . /home/appRUN npm install -g gulpRUN npm installCOPY start.sh /CMD ["./start.sh"]

So after the whole include of the app + npm installation inside my nginx I start my container with the start.sh script.

The content of start.sh:

#!/bin/bashsed -i 's@my-url@'"$DATA_ACCESS_URL"'@' configs/config.jsongulp buildrm -r /usr/share/nginx/html///cp right folders which are created by gulp build to /usr/share/nginx/html...//start nginx container/usr/sbin/nginx -g "daemon off;"

So the build will happen when my container starts. Not the best way of course but it's all for the needs of the developers. Have an easy local frontend.

The sed command will perform a replace on the config file which contains something like:

{  "service_base": "my-url",}

So my-url will be replaced by my the content of my environment variable which I willd define in my docker run command.

Than I'm able to perform.

docker run -d -p 80:80 -e DATA_ACCESS_URL=https://mybackendurl.com app:latest

And every developer can use the frontend locally and connect with their own backend URL.