简体   繁体   中英

Docker node service return ECONNRESET network error when running npm install in docker container

I have set up a simple laravel application using docker-compose.

Everything works fine, aside from node service.

When I run docker-compose run --rm node npm install in the project folder I receive the following error after the command works for some time在此处输入图像描述

Also here is my docker-compose.yml file

version: "3.7"

services: app: build: args: user: delll uid: 1000 context: ./ dockerfile: Dockerfile image: landing-app restart: unless-stopped working_dir: /var/www/ volumes: -./:/var/www networks: - landing

nginx:
    image: nginx:alpine
    restart: unless-stopped
    ports:
    - 8000:80
    volumes:
    - ./:/var/www
    - ./docker-compose/nginx:/etc/nginx/conf.d/
    networks:
    - landing

node:
    image: node:15.5-alpine3.10
    working_dir: /assets
    volumes: 
        - ./:/assets
    command: "npm run watch" 

db:
    image: mysql:8
    restart: unless-stopped
    environment:
        MYSQL_DATABASE: ${DB_DATABASE}
        MYSQL_ROOT_PASSWORD: ${DB_PASSWORD}
        MYSQL_PASSWORD: ${DB_PASSWORD}
        MYSQL_USER: ${DB_USERNAME}
    networks:
        - landing

networks: landing: driver: bridge

FYI After facing the same issue and looking at DOZENS of posts including this one (whose solution seems mighty complicated) what worked was a simple proxy config to be passed to npm itself. This fixed it during the docker build process. All I had to do was add these lines to my Dockerfile BEFORE running the npm install command:-

RUN npm config set http-proxy http://<my company proxy>:8099

RUN npm config set https-proxy http://<my company proxy>:8099

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