skålfyfan
skålfyfan

Reputation: 5281

Dockerfile build volume changes not reflected on mounted local folder? (OS X / boot2Docker)

Using docker-compose I have a Dockerfile which builds an environment for a Sails JS app. In my Dockerfile I generate a new Sails scaffold project using sails new . (a folder mapped to my local filesystem through docker-compose).

When I run docker-compose build everything seems to build successfully. I follow through with a docker-compose up -d on my local machine. Then I navigate to the folder that is mapped on the host machine to my local, the folder where on the HOST machine (vm) I generated the new Sails project. I'm expecting to see all the files that were generated on the HOST machine during docker-compose build sitting there in my local folder. The folder is BLANK though? What's up?

My basic docker-compose file:

node:
  restart: "always"
  build: ./cnt/node
  ports:
    - "8080:8080"
  volumes:
    - ./src:/var/www/html
  # DEBUG: conveniently used to keep a container running
  command: /bin/bash -c 'tail -f /dev/null'

NOTE: ./src is my local folder where my source code will reside. This is mapped to /var/www/html (webroot) on the HOST machine.

Here are the last couple lines from the Dockerfile found in ./cnt/node used to generate the Sails scaffold:

WORKDIR /var/www/html
RUN sails new .
RUN touch test.txt

Everything runs successfully when I execute (no errors):

docker-compose build
docker-compose up -d

When done I cd src to examine the source directory where I expected to see my Sails app scaffold, but it's EMPTY. What the heck?! There were no errors? What am I missing?

Is it something to do with the docker-compose file and that the image I'm buidling is built via build: ./cnt/node and LATER I mount the volumes in compose file? Do I need to mount the VOLUMES first before I generate the Sails scaffold?

Thanks!

Upvotes: 1

Views: 1553

Answers (1)

dnephin
dnephin

Reputation: 28120

Volumes are only mounted during run time, build is specifically designed to be reproducible, so nothing external is allowed during build.

You'll have to generate the scaffolding on the host by using docker-compose run node ...

Upvotes: 2

Related Questions