How to create a human readable name for a volume from an image build VOLUME

Newbie question:

I have created an alpine docker image and created+populated a volume in the Dockerfile with

mkdir /opt

however, that creates a rather unrecognisable volume name, which seems impossible to change. The VOLUME docs don’t seem to say how it’s possible to rename a volume created this way.

If it’s possible to create a volume with docker volume create NAME

If I want to mount the volume to another container I need to know that volume id rather than a nice friendly name - is this possible?

If you explicitly mount a volume or host directory with docker run -v on the exact same path, you get to choose the name. If you need Docker to create the volume with the contents specified in the Dockerfile, it must be a named volume and it must not exist before the docker run invocation (don’t manually docker volume create it) (see here).

docker run --volumes-from will mount all of the volumes from one container into another on the exact same path; but you don’t have a whole lot of control over how it works, and you still need to know the other container’s name or ID. It’s probably easier to explicitly specify volume names or paths.

As a general design question, multi-container Docker setups tend to be happier if they can communicate with each other over the network rather than by sharing files. This isn’t always a practical answer, but if you’re building new services and one is sending data to another, building a small HTTP service tends to work better within Docker than trying to use a shared volume.

Thanks David, I can pre-create the volume before starting the container, so will create it with a suitable name there. I’m in the process of getting the container dependency/design issues nutted out, so it’s not currently cast in stone where things will live. These are log files that get written by a running app, so need to be exposed and pushed to a log consumer somewhere, so I was just trying to get my head around the usefulness of defining volumes in the docker run phase vs creation outside.