Unknown MySQL server host 'mysql'

OK - I found the solution.

I edit the docker-compose.yml file and add a aliases flag for the cms-db service. Now the cms-db Container is linked in the cms-web Container again with “mysql” and everything is working as before.

And the reason it took so long for me to find the solution was: I didn’t understand how to access the default network, because the examples I found always mention a concrete docker network. So I missed the keyword “default” and my tries failed.

    cms-db:
        image: mysql:5.7
        volumes:
            - "./shared/db:/var/lib/mysql:Z"
        environment:
            - MYSQL_DATABASE=cms
            - MYSQL_USER=cms
            - MYSQL_RANDOM_ROOT_PASSWORD=yes
        mem_limit: 1g
        env_file: config.env
        restart: always
        networks:
           default:
             aliases:
                - mysql
3 Likes