1

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!

skålfyfan
  • 4,931
  • 5
  • 41
  • 59
  • Where is your src folder? Only /Users/... is shared between your host and the VM: http://stackoverflow.com/a/33998695/6309 – VonC Dec 04 '15 at 05:42
  • @VonC yes. Aware of the /Users folder restriction and my src folder is in a subfolder of /Users – skålfyfan Dec 04 '15 at 15:37

1 Answers1

2

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 ...

dnephin
  • 25,944
  • 9
  • 55
  • 45
  • Correct answer! Unfortunately `docker-compose run node ...` will generate a new image layer and that's something I want to avoid when generating the scaffold. Resolved my issue by creating a startup script (startup-check.sh) and adding this to the command option in docker-compose: `command: /bin/bash -c '/startup-check.sh && [your_standard_container_command]'` – skålfyfan Dec 07 '15 at 17:19
  • `docker-compose run node` doesn't create a new image layer, but it does create a new container. You can use `docker-compose run --rm node` to have the container removed immediately after it's done, if that is a concern. Creating new containers is pretty lightweight, so it probably doesn't need to be a concern. An entrypoint script (as you described) is another common option. – dnephin Dec 09 '15 at 00:13