4

I'm trying to run my ng2 app in docker. I have the Docker file:

FROM ubuntu:latest

RUN apt-get update

#Install curl & git
RUN apt-get -qq -y install curl
RUN apt-get install -yqq git


#Download and install nodejs-6
RUN curl -sL https://deb.nodesource.com/setup_6.x -o nodesource_setup.sh
RUN bash nodesource_setup.sh
RUN apt-get install -yqq nodejs
RUN apt-get install -yqq build-essential
RUN npm install -g angular-cli


#Clone the project
RUN git clone https://github.com/moravianlibrary/RecordManager2.git

WORKDIR /RecordManager2

#Checkout webapp_jobs_branch
RUN git checkout webapp_jobs_branch


#Go to the gui directory
WORKDIR /RecordManager2/cz.mzk.recordmanager.webapp.gui/gui

EXPOSE 4200

RUN npm install

CMD ["ng", "serve"]

building and running finish without errors:

docker build -t rm-gui .
docker run --name gui -dp 4200:4200 rm-gui

After running the app I can see that app is really running:

CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS                    NAMES
caa4f1f820d6        rm-gui              "ng serve"          23 minutes ago      Up 23 minutes       0.0.0.0:4200->4200/tcp   gui

but when I open the page http://localhost:4200/ I see an error This site can’t be reached . What am I doing wrong?

1

1 Answer 1

1

in your package.json file set the following start command

  "scripts": {
    "ng": "ng",
    "start": "ng serve -H 0.0.0.0",
    .....
  },

in your Dockerfile replace the last line with

CMD ["npm", "start"]
Sign up to request clarification or add additional context in comments.

1 Comment

did not work the container started restarting itself every few seconds or so.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.