Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 888
MalcLear Avatar asked Jul 24 '19 03:07

MalcLear


People also ask

Does docker compose automatically create volume?

Using the latest compose version (3) you can create your volumes automatically.

Where does docker compose create volume?

These volumes are created inside /var/lib/docker/volume local host directory. As we can see, we don't have to specify the host directory. We just need to specify the directory inside the container. If we remove the volume instruction from the docker-compose.


2 Answers

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.

like image 89
atline Avatar answered Oct 08 '22 21:10

atline


According to the docs the image creates a volume in:

/var/lib/pgadmin

This is the working directory in which pgAdmin stores session data, user files, configuration files, and it's configuration database. Mapping this directory onto the host machine gives you an easy way to maintain configuration between invocations of the container.

A docker inspect container_id shows:

"Mounts": [
    {
        "Type": "volume",
        "Name": "70c8ae8e1de3e5d6c71fa9c63930cc75761132f4fdb75a2982b32454313b78c6",
        "Source": "/var/lib/docker/volumes/70c8ae8e1de3e5d6c71fa9c63930cc75761132f4fdb75a2982b32454313b78c6/_data",
        "Destination": "/var/lib/pgadmin",
        "Driver": "local",
        "Mode": "",
        "RW": true,
        "Propagation": ""
    }
],

So it seems that an anonymos volume is created each time In order to reuse the volume use docker-compose start/stop instead of docker-compose up/down. Similar issue discussed here,

like image 42
b0gusb Avatar answered Oct 08 '22 20:10

b0gusb