How do I mount a host directory as a volume in docker compose

前端 未结 5 1401
时光取名叫无心
时光取名叫无心 2020-12-07 08:59

I have a development environment I\'m dockerizing and I would like the ability to livereload my changes without having to rebuild docker images. I\'m using docker compose be

5条回答
  •  余生分开走
    2020-12-07 09:47

    It was two things:

    I added the volume in docker-compose.yml:

    node:
      volumes:
        - ./node:/app
    

    I moved the npm install && nodemon app.js pieces into a CMD because RUN adds things to the Union File System, and my volume isn't part of UFS.

    # Set the base image to Ubuntu
    FROM    node:boron
    
    # File Author / Maintainer
    MAINTAINER Amin Shah Gilani 
    
    # Install nodemon
    RUN npm install -g nodemon
    
    # Add a /app volume
    VOLUME ["/app"]
    
    # Define working directory
    WORKDIR /app
    
    # Expose port
    EXPOSE  8080
    
    # Run npm install
    CMD npm install && nodemon app.js
    

提交回复
热议问题