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 to connect to PostgreSQL server that's run on docker
  • automatically start /etc/init script in IBM Bluemix container
  • SparqlVerse issue with Docker
  • How to define multiple tasks in elastic beanstalk docker json
  • How to block a Docker registry?
  • Different hashes while pulling from hub and pushing to registry
  • 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"
    

  • How to figure out if docker master or agent running
  • Kubernetes Jenkins plugin - slaves always offline
  • How to run headless browser testing in docker container
  • How to support interactive /bin/bash in docker exec command using python dockerpy module on windows?
  • Establish PSSession to Windows docker container from remote machine (not container host)
  • at command inside docker container
  • 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.