I'm trying to build an image that I can use to deploy multiple containers with an angular application.
The purpose is to have the container running the command ng server --host ${HOST} --port ${PORT} --disable-host-check
and customizing the ENV var with docker run
or docker-composes
like :
default env var (in the Dockerfile)
docker run -d --name bar -p 10000:4200 -v /path/to/AngularApp:/www me/ngx-admin:dev
will runng server --host 0.0.0.0 --port 4200 --disable-host-check
custom :
docker run -d --name foo -e HOST='dev.my-domain.fr' -e PORT='4201' -p 10000:4201 -v /path/to/AngularApp:/www me/ngx-admin:dev
will runng server --host dev.my-domain.fr --port 4201 --disable-host-check
If I understood ENTRYPOINT
and CMD
correctly, if I use both as "exec form" (JSON Array), the CMD
is concatenated behind ENTRYPOINT
as params.
Thanks!
Here is my Dockerfile (with the CMD I tried) and the different errors I have :
# base image
FROM node:12
# install chrome for protractor tests
RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add -
RUN sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list'
RUN apt-get update && apt-get install -yq google-chrome-stable
# set working directory
WORKDIR /www
# add `/www/node_modules/.bin` to $PATH
ENV PATH /www/node_modules/.bin:$PATH
# install and cache app dependencies
COPY package.json /www/package.json
RUN npm install -g @angular/cli@7.3.9
RUN npm install
# add app
COPY . /www
# default env
ENV HOST 0.0.0.0
ENV PORT 4200
EXPOSE ${PORT}
# start www
ENTRYPOINT ["ng", "serve"]
CMD ["--host", "0.0.0.0", "--port", "4200", "--disable-host-check"] # WORKS!!
#CMD ["--host", "${HOST}", "--port", "${PORT}", "--disable-host-check"] # cf. ERR 1
#CMD ["--host", "${HOST}", "--port", ${PORT}, "--disable-host-check"] # cf. ERR 2
#CMD ["--host", "${HOST}", "--port", "4200", "--disable-host-check"] # cf. ERR 3
ERR 1
Cannot parse arguments. See below for the reasons.
Argument port could not be parsed using value "".Valid type(s) is: number
docker inspect
"Path": "ng",<br>
"Args": [
"serve",<br>
"--host",<br>
"${HOST}",<br>
"--port",<br>
"${PORT}",<br>
"--disable-host-check"
],
ERR 2
Error: Project '/bin/sh' does not support the 'serve' target.
at ServeCommand.initialize (/www/node_modules/@angular/cli/models/architect-command.js:58:19)<br>
at async ServeCommand.validateAndRun (/www/node_modules/@angular/cli/models/command.js:127:9)<br>
at async Object.runCommand (/www/node_modules/@angular/cli/models/command-runner.js:178:24)<br>
at async default_1 (/www/node_modules/@angular/cli/lib/cli/index.js:32:31)
docker inspect
"Path": "ng",<br>
"Args": [
"serve",<br>
"/bin/sh",<br>
"-c",<br>
"[\"--host\", \"${HOST}\", \"--port\", ${PORT}, \"--disable-host-check\"]\t\t# ERR 2"
],
ERR 3
rowserslist: caniuse-lite is outdated. Please run next command `npm update`
getaddrinfo EAI_AGAIN ${HOST}<br>
Error: getaddrinfo EAI_AGAIN ${HOST}
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:60:26)
docker inspect
"Path": "ng",<br>
"Args": [<br>
"serve",<br>
"--host",<br>
"${HOST}",<br>
"--port",<br>
"4200",<br>
"--disable-host-check"
],