Install node_modules inside Docker container and synchronize them with host

前端 未结 10 1395
旧巷少年郎
旧巷少年郎 2020-12-12 11:33

I have the problem with installing node_modules inside the Docker container and synchronize them with the host. My Docker\'s version is 18.03.1-ce, build

10条回答
  •  醉话见心
    2020-12-12 12:04

    I know that this was resolved, but what about:

    Dockerfile:

    FROM node
    
    # Create app directory
    WORKDIR /usr/src/app
    
    # Your other staffs
    
    EXPOSE 3000
    

    docker-composer.yml:

    version: '3.2'
    services:
        api:
            build: ./path/to/folder/with/a/dockerfile
            volumes:
                - "./volumes/app:/usr/src/app"
            command: "npm start"
    

    volumes/app/package.json

    {
        ... ,
        "scripts": {
            "start": "npm install && node server.js"
        },
        "dependencies": {
            ....
        }
     }
    

    After run, node_modules will be present in your volumes, but its contents are generated within the container so no cross platform problems.

提交回复
热议问题