postgresqldockerpgadminpgadmin-4

PGAdmin creates new random volume with each "docker-compose up"


Each time I run the following command:

> docker-compose up -d

... in a directory where I have the following docker-compose.yaml file, I get a new, randomly named volume.

docker-compose.yaml:

version: '3.7'

services:

  pgadmin:
    restart: always
    image: dpage/pgadmin4
    container_name: pgadmin_container
    environment:
      PGADMIN_DEFAULT_EMAIL: ${PGADMIN_DEFAULT_EMAIL:-foobar}
      PGADMIN_DEFAULT_PASSWORD: ${PGADMIN_DEFAULT_PASSWORD:-password}
    ports:
      - "${PGADMIN_PORT:-8080}:80"

output at command line:

C:\postgres> docker-compose up -d
Creating network "postgres_default" with the default driver
Creating pgadmin_container ... done
C:\postgres> docker volume ls
DRIVER              VOLUME NAME
local               3ee8f970ff477052c6fba9001575a0efa0254deb8dcf73ca97d0422231c74931
C:\postgres> docker-compose down
Stopping pgadmin_container ... done
Removing pgadmin_container ... done
Removing network postgres_default
C:\postgres> docker-compose up -d
Creating network "postgres_default" with the default driver
Creating pgadmin_container ... done
C:\postgres> docker volume ls
DRIVER              VOLUME NAME
local               3ee8f970ff477052c6fba9001575a0efa0254deb8dcf73ca97d0422231c74931
local               705dad9c905eb8f1679a9ee4ff290363c40f5285b8048204cab44bce26916845
C:\postgres>

You'll see that where there was one volume with a 64-char name after the first "up", after the second call to "docker-compose up", there were two. This pattern continues.

What is causing the randomly named volumes? How do I prevent their creation of force the system re-use them?

I've actually edited down my docker-compose.yaml file to get to the bare minimum to recreate the problem. There is also, actaully, a Postgres database being started with the same file.


Solution

  • If you use docker inspect dpage/pgadmin4 to have a look, you will see next:

    "Volumes": {
        "/var/lib/pgadmin": {}
    }, 
    

    This means in its Dockerfile, it defines a Anonymous volumes like next:

    VOLUME ["/var/lib/pgadmin"]
    

    Above will make volume name changes every time when you up/down service. To make it not change, you could override it with Named volumes, like next:

    version: '3.7'
    
    services:
      pgadmin:
        restart: always
        image: dpage/pgadmin4
        container_name: pgadmin_container
        environment:
          PGADMIN_DEFAULT_EMAIL: ${PGADMIN_DEFAULT_EMAIL:-foobar}
          PGADMIN_DEFAULT_PASSWORD: ${PGADMIN_DEFAULT_PASSWORD:-password}
        ports:
          - "${PGADMIN_PORT:-8080}:80"
        volumes:
          - my-data:/var/lib/pgadmin
    
    volumes:
        my-data:
    

    You can refer to this & this to learn more about it.