Docker Community Forums

Share and learn in the Docker community.

Populating data in volume mounts

I’m trying to figure out what allows data to be passed from the image to a host volume mount, For instance

FROM alpine
CMD mkdir -p /some/volume && echo "Hello World" > /some/volume/test.txt
VOLUME /some/volume

allows test.txt to show up in a mounted directory, like

docker run -d --name=docker-test -v $HOME/.config/docker-test:/some/volume docker-test
ls $HOME/.config/docker-test
test.txt

But,

FROM alpine
RUN mkdir -p /some/volume && echo "Hello World" > /some/volume/test.txt
VOLUME /some/volume

does not.

docker run -d --name=docker-test -v $HOME/.config/docker-test:/some/volume docker-test
ls $HOME/.config/docker-test

My end goal is to pass some pre-existing data to a host mounted volume to allow for edits and additions. Specifically, I’m trying to mount /usr/share/netdata/web in my custom netdata image to allow for custom dashboards.