1

If I'm going to run nginx like so:

docker run -i -t -p 80:80 \
-v /docker/dev:/dev \
-v /docker/var/www:/var/www \
-v /docker/var/log/nginx:/var/log/nginx \
-v /docker/etc/nginx:/etc/nginx \
--name clmnginxbash quasaur/nginximage /bin/bash

...and I'm using the Docker HOST's filesystem to store nginx's configs and the website itself, I shouldn't have to include a VOLUME statement for those shares, or should I?

VOLUME ["/etc/nginx", "/var/www","/var/log/nginx"]

In fact, shouldn't I be able to remove those directories from the image in the Dockerfile since they're not going to be used?

RUN rm -rf /usr/share/nginx/www /etc/nginx /var/log/nginx

Thanks for your feedback!

Quasaur
  • 165
  • 6

1 Answers1

1

Specifying -v at run or volumes in the VOLUME instruction both mount a volume that bypasses UFS to store persistent data. See https://docs.docker.com/terms/layer/#ufs-def. It is an actual mount in the container:

$ docker run --rm ubuntu mount | grep mnt

Nothing mounted in the container. Let's try that again with a -v /mnt:

$ docker run --name mount -v /mnt ubuntu mount | grep mnt
/dev/sda1 on /mnt type ext4 (rw,relatime,data=ordered)

Cool, we have a persistent mount. But we didn't specify a place on the host to store it... where does it actually live?

$ docker inspect --format '{{ .Volumes }}' mount
map[/mnt:/mnt/sda1/var/lib/docker/vfs/dir/3d0eff68f9db4821821812f9e363c1e6058105de8a7a04ecfda113e8def9848a]

As you have pointed out already, you can map this mount to a directory on the host by prefixing it with something:

$ docker run --rm -v /folder/on/host:/mnt

So, to answer your two questions, no, the VOLUME instructions in the Dockerfile are not required. Should you remove them? I guess, assuming you will never have persistent data in the containers without specifying -v.

Andy Shinn
  • 4,211
  • 8
  • 40
  • 55
  • Thank you for your timely feedback! Another question: how does Docker handle rights on the Docker HOST when it shares its file system with the Docker container (i'm thinking about an Nginx container's expectation of, say, /var/www on the Docker HOST having permissions for user www-data)?? – Quasaur Sep 08 '14 at 20:34
  • It is going assume the user ID of the user in the container. If you have a user www with ID 1000 in the container and user docker with id 1000 on the host, when www writes a file to that mapped host directory, it will appear as owned by docker on the host. – Andy Shinn Sep 08 '14 at 23:10