0

I am trying to dockerize my angular app. Below is my docker file, but I could not access the app in the port 4200. I don't know what is wrong in my configuration. It is angular-cli app. Can you please help me find it?

FROM node:alpine

WORKDIR /app

COPY ./package.json .

RUN npm install

COPY . .

EXPOSE 80 4200

CMD ["npm", "run", "start"]

docker container run --publish 4200:4200 ngdockerapp

0ab397bc6233        ngdockerapp         "npm run start"     37 seconds ago      Up 35 seconds       80/tcp, 0.0.0.0:4200->4200/tcp   ngdockerapp_ng_1

But I couldn't access the app in the host with 4200 port. I could see it is starting inside the container fine.

Project Link:

https://github.com/manojp1988/ngDockerApp.git

Manoj
  • 5,707
  • 19
  • 56
  • 86

2 Answers2

2

The problem is, you're using ng serve in the container without specifying the host. ng serve will by default only serve for 127.0.0.1. you can change that by using the --host parameter.

documentation about serve: https://github.com/angular/angular-cli/wiki/serve

I added a pullrequest to your repo to fix it: https://github.com/manojp1988/ngDockerApp/pull/1

Isitar
  • 1,286
  • 12
  • 29
0

If you run docker exec -it <container_id> /bin/bash, you can access the container. check this out How do I get into a Docker container?

Anil Cherukuri
  • 121
  • 1
  • 6