how does docker map volume names in docker compose file to volumes on system

Viewed 458

I am migrating a tvial docker mail server from one system to another. I set this up some time ago, and vaguely remember the steps, but not every detail. I copied my mail data and mail state volumes to the new system, but when I went to run docker on the new system I was confused. The old system shows this in docker compose:

    - maildata:/var/mail
    - mailstate:/var/mail-state
volumes:
  maildata:
    driver: local
  mailstate:
    driver: local

But the volumes have different names:

$ sudo docker volume ls
DRIVER              VOLUME NAME
local               tvial_docker-mailserver_maildata
local               tvial_docker-mailserver_mailstate

If I inspect the running instance it shows that it is bound to the correct volume.

How do I reproduce this on the new system?

EDIT:

I ran the docker container on the new system and the maillog container seems to be constructed using a similar nomenclature:

Creating volume "tvial_docker-mailserver_maillogs" with local driver

So this is no longer a pressing issue, but I reviewed the dockerfile for this container, and I don't see where the name is coming from. Can anyone tell me?

1 Answers

The resources are prefixed with the project(deployment) name.
This can be specified using the -p flag when you run the docker-compose up command. If not specified, the project name defaults to the name of the directory to whom your docker-compose.yaml file belongs to.

Official documentation here: https://docs.docker.com/compose/reference/envvars/#compose_project_name . Relevant extract for the question:

COMPOSE_PROJECT_NAME:
Sets the project name. This value is prepended along with the service name to the container on start up. For example, if your project name is myapp and it includes two services db and web, then Compose starts containers named myapp_db_1 and myapp_web_1 respectively.

Related