Docker Community Forums

Share and learn in the Docker community.

Run Dockerfile commands from one image inside a volume mounted via a different image


(Mvaneijgen) #1

I have a working docker-compose.yml file that sets up a website, database and nodejs. Within a website image I mount a volume in the root of my project in which I will develop my site (theme). In theses sites I regularly use Bower and Gulp to manage libraries and compile my static files like SASS. Because this site is being mounted via the website image I don’t see a way to run my npm, bower and gulp commands inside a other container and not from my host machine (running the npm, bower and gulp command is what I do right now and I would like to shield this off from the host, because running multiple projects with multiple dependencies versions is now a nightmare and I thought Docker would solve this).

What my project file now looks like is

docker-compose.yml
Dockerfile
/my-theme
  bower.json
  gulpfile.js
  package.json
  ...REST OF THE THEME FILES...

In the Dockerfile I run node,npm install and all the rest of the necessary Gulp and Bower commands I also run getting it to work on my host machine, but I just don’t get how I can get these commands to run only in the /my-theme folder which is mounted (volume:) in the root of my project folder.

Here is a version of my project file hosted on Github https://github.com/mvaneijgen/docker-wordpress-with-gulp I think what I somehow need to do is set the working_dir: of node: in my services: to the folder in the root, but I just can’t get it figured out and would love it if anyone could shine some light on how this should work.


(Sam) #2

WORKDIR /folder

is the dockerfile command

working_dir /folder is the docker compose syntax


(Mvaneijgen) #3

@sdetweil I know what the docs say, but it is not working for me and I think I’m looking in the wrong place or didn’t get how to set the /folder correctly.


(Sam) #4

Dockerfile
run mkdir /my_theme (if not already created)
Working_dir /my_theme
copy (or add) from docker host to image
/my-theme
bower.json
gulpfile.js
package.json
…REST OF THE THEME FILES…