php_network_getaddresses: getaddrinfo failed error in Docker's adminer

The problem with your setup is because of the environment variable DB_PATH_HOST. You have setup everything fine in your compose file. but before running docker-compose you are supposed to define the environment variable DB_PATH_HOST. Since the environment variable is not defined it throws an error. See this for more details on Environment variables and it's precedence in Docker.

So what you should have done is, Before starting docker container you should have defined the environment variable either by defining it in compose file or exporting it in shell as shell variable before running docker-compose or should have used env file or by using ENV instrction in dockerfile. (These are all the possible ways of defining environment variables and I've listed all of them the method that comes first takes priority. refer this for more info).

So the proper docker-compose.yml file should be as follows.

version: '3.2'
services:
   db:
        image: mysql:5.6.41
        restart: always
        environment: 
            MYSQL_ROOT_PASSWORD: 1
            DB_PATH_HOST: /tmp/mysql #this is the host location where mysql data will be stored.
        volumes:
            - ${DB_PATH_HOST}:/var/lib/mysql

    phpmyadmin:
        depends_on:
          - db
        image: phpmyadmin/phpmyadmin
        restart: always
        ports:
          - 8082:80
        environment:
          PMA_HOST: db
          MYSQL_ROOT_PASSWORD: 1

Now coming to the next point I see that from your discussions you have concluded that removing volumes from the db container fixed your problem. But actually not. How?

First let me explain why volume is used here. The data generated my mysql should be stored somewhere. Docker by default runs containers in non-persistant mode, which means all the data generated by the running docker conatiner will be erased when that container is brought down/killed. So in order to persist(store/save) data we use volumes. There are different types of volumes used in docker. I encourage you to read Storage documentation of docker for more details. The type of volume used here is a bind mount which is, You bind a host directory to a docker directory and docker stores all the data directly in host machine such that even if docker container is brought down data is still preserved.

Hence if you don't use volumes in mysql all the db changes irrespective of whatever you do, will be lost whenever the container is stopped.

Bonus Poits:

  1. By default MySQL container doesn't allow remote connections. So if you want to access mysql from anywhere else apart from phpmyadmin. You have to allow remote connections.
  2. Since we are preserving the data here the root password will be set only on the first time whenever you start mysqll container. From next time onwards root password environment variable will be ignored.
  3. If you log into docker containers using docker exec mostly you can see that you will be root. That's because whenever you create a docker container with Dockerfile by using either docker build or docker-compose build unless you specify an instruction on Dockerfile to create and use a new user docker will run everything as root user.
  4. Now whenever you run the above compose file. You can see that the mysql data location's ownership will be changed. It's because whenever you mount a host directory to docker, Docker changes the file permission according to the user and group as per that container's Dockerile definition. Here mysql has defined a user and group called mysql and the uid and gid is 999. hence /tmp/mysql will be havng 999:999 as ownership. If these id's are mapped with any other user account in your system you will see those names instead of ids whenever you do ls -al in host machine. If id's are not mapped then you will see the id's directly.
  5. I've used /tmp/mysql as mysql data directory for an example. Pleae don't use the same as the data in /tmp will be removed whenever there is a system restart.