I am trying to create a docker container to use for Angular development.
Using a nearly identical dockerfile to the one below, I was able to create a development container for React.
FROM node:8.9.0
ENV NPM_CONFIG_LOGLEVEL warn
ARG app_env
ENV APP_ENV $app_env
RUN mkdir -p /app1
WORKDIR /app1
COPY ./app1 ./
COPY app1/package.json /app1
RUN npm install
RUN npm update
RUN npm install -g typescript
EXPOSE 4200
RUN chmod a+x /app1/node_modules/.bin/*
ENTRYPOINT ["tail", "-f", "/dev/null"]
#ENTRYPOINT npm start
To run the container I use:
docker run -i -t -p 4200:4200 -v /var/react/{your app name}/{Your apps sub folder}/src:/{ Your apps sub folder } /src {container ID}
I then enter the container and run npm start
or npm start 0.0.0.0:4200
. Everything compiles successfully and says it should be running on localhost:4200
but I get a connection refused error.
I'll reiterate, using an identical dockerfile, I am able to do this with react. The only differences between the files are port numbers and mounted volumes.
As such, this makes me think it's something to do with the Angular configuration but I don't know where to begin looking. Any ideas?
thanks!
FROM node:lts RUN mkdir /home/node/app && chown node:node /home/node/app RUN mkdir /home/node/app/node_modules && chown node:node /home/node/app/node_modules WORKDIR /home/node/app USER node COPY --chown=node:node package. json package-lock. json ./ RUN npm ci --quiet COPY --chown=node:node . .
The dockerfile comprises of a multi-stage docker build, which is divided into the following stages: Building the angular source code into production ready output. Serving the application using a NGINX web server.
As I suspected, it was an Angular config issue. All I needed to do was change my package.json
file.
From:
"scripts": {
"ng": "ng",
"start": "ng serve"
To:
"scripts": {
"ng": "ng",
"start": "ng serve --host 0.0.0.0 --disable-host-check"
My Dockerfile stayed the same.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With