As part of a bigger setup, I have a multi-stage Docker build with Docker Compose that has a builder container with some data in /var/www. When I build the second stage container called application my Dockerfile has these instructions
ARG APPLICATION_BUILDER
FROM $APPLICATION_BUILDER as builder
FROM busybox
COPY --from=builder --chown=www-data:www-data /var/www /var/www
VOLUME /var/www
ENTRYPOINT ["tail"]
CMD ["-f", "/dev/null"]
The builder Dockerfile is:
FROM ubuntu:16.04
ARG APPLICATION_SOURCE_FOLDER
COPY --chown=www-data:www-data ${APPLICATION_SOURCE_FOLDER} /var/www
When I start the builder container it has all the data in /var/www as expected. However, when I start the application container using: docker run -it <IMAGE> it contains nothing in /var/www
If I remove the VOLUME /var/www line in the Dockerfile then the data appears as expected. But I don't understand why the VOLUME instruction would make the data disappear, I thought it is meant to export the contents of /var/www/ as a volume?
Do I need to specify a -v when I do docker run in addition to the VOLUME instruction?