简体   繁体   中英

How to access docker app in the host machine?

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

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

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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM