Make Dockerfile VOLUME behave like docker-compose volumes

I am trying to setup a Dockerfile to mount my host directory to my specified docker container directory (so code changes will be reflected immediately). When I run docker run -p 3000:3000 -d -v ~/Projects/test:/app test the files are mounted and everything works fine. However, once I close the container, the file changes don’t stay within the container like the changes would if I were running volumes from a docker-compose file.

Here is my Dockerfile:

  • How do apply Puppet class locally
  • Redis memory usage, ZSET and docker
  • How do I make a comment in a Dockerfile?
  • Symfony app in Docker doesn't work
  • run batch in wordpress docker container
  • Docker. Show stopped containers
  • FROM node:onbuild
    EXPOSE 3000
    RUN mkdir /app
    VOLUME ./:/app/
    WORKDIR /app/
    RUN npm install -g nodemon
    CMD nodemon server.js
    

    Here is a working docker-compose.yml:

    test:
      build: ./
      volumes:
        - ./:/app/
      working_dir: /app/
      command: npm start 
      ports:
        - "3000:3000"
    

  • prior storage driver “aufs” failed: driver not supported Error starting daemon: error initializing graphdriver: driver not supported
  • php-fpm & nginx in separated docker container, can not execute .php file
  • Can't install scipy
  • docker command line list arguments
  • How to write docker file to run a docker run command inside an image
  • How to run a database independent of a Rails app?
  • One Solution collect form web for “Make Dockerfile VOLUME behave like docker-compose volumes”

    The VOLUME command in Dockerfile has a slightly different meaning:

    1. you cannot define mounted volumes within a Dockerfile
    2. it’s only used for specifying inter-container volumes

    So in your Dockerfile, VOLUME ./:/app/ must be changed to VOLUME /app/. Your docker-compose definition will tell docker to mount local dir . to /app in the container.


    The -v option and the volumes tag in docker-compose work the same way. The host directory is mounted to a container directory. Any file which was present in the image in the container directory will be replaced by the files from the host directory.

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.