Docker container doesn't reload Angular app

后端 未结 5 670
忘掉有多难
忘掉有多难 2020-12-01 18:32

I have some issue with ng serve in my docker container running by docker-compose.

Dockerfile

FROM node:7.1

RUN mkdir -p /u         


        
5条回答
  •  臣服心动
    2020-12-01 18:49

    Webpack uses a port to do live reload of the application. That port is 49153 by default.

    You have to expose and bind that port in the container to the host port and that should solve your problem.

    So, add this to your Dockerfile.

    FROM node:7.1
    
    RUN mkdir -p /usr/src/app
    WORKDIR /usr/src/app
    COPY package.json /usr/src/app
    RUN npm install
    RUN npm install -g angular-cli
    COPY . /usr/src/app
    
    EXPOSE 4200 49153
    
    CMD [ "npm", "start" ]'
    

    And this to your docker-compose.yml.

    web:
        build: .
        ports:
            - '8089:4200'
            - '49153:49153'
        volumes:
            - .:/usr/src/app/
        environment:
            - NODE_ENV=dev
        command: bash -c "npm start"
    

提交回复
热议问题