9

I want to build a docker image that is based on dockerage/apache-mellon which has a volume on /var/www. I want to build my web app inside the docker container when I'm building it inside a temporary directory and than copy the files to /var/www with the following commands in my Dockerfile:

WORKDIR /tmp
COPY . /tmp
RUN ./node_modules/gulp/bin/gulp.js
RUN cp -R /tmp/dist/ /var/www

The docker build process finishes without any errors, but the files do not get copied to /var/www. Is there a way to copy files to a location which is declared as docker volume during build?

Oskar Jauch
  • 103
  • 1
  • 1
  • 6

1 Answers1

4

You can't do it during the build. The volume is something that interacts with containers, not images. You could create an entrypoint script that copies the files to the volume when the container is launched, but i'm not sure that this would be a good solution

Derek
  • 1,826
  • 18
  • 25
  • Does it make a difference if I copy files inside of the image or from the host to the image? Because in my previous solution I just copied the files to the image after I build them on my host and it worked fine with: `RUN mkdir /var/www/[app_name]` `COPY ./dist/ /var/www/[app_name]/` But I don't like this solution much, because you have to do other build steps before you can run `docker build`.. – Oskar Jauch Jun 24 '16 at 11:29
  • It does not make a difference. The first time you run a container from this image, the files will be there because the volume gets created. But once it is created, copying files to it from a Dockerfile won't do anything unless you first delete the volume. – Derek Jun 24 '16 at 11:49