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 manage concurrency in docker push and docker pull?
  • How to copy /var/lib/docker with overlayfs directory structure with data *as-is* without increasing the storage space
  • Reach one concourse task's container from another one
  • When I am going to extend mysql docker image, I can't add my own entrypoint shell
  • Docker-compose: no access to WordPress files
  • Replacing a particular instance on AWS Elastic BeanStalk?
  • 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:

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

  • Should I use save/load or export/import for my application using Docker? And an additional uncertainty
  • Why doesn´t docker-compose env_file work but environment does?
  • Vagrant env variable to Docker build
  • Gui application in docker. What about drivers?
  • Define application properties on build using Spring Boot and Maven
  • Cannot SSH using private key while building Docker image
  • 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.