Running MySQL without password in Docker Compose

It is possible to access a MySQL or MariaDB database in Docker Compose, even without knowing a password.

Warning! Do this only for development purposes! It is completely insecure to keep a passwordless root in a database.

In my case I needed to create a dump from the data. I only had the /var/lib/mysql folder copied from production server. The folder was mounted in the docker container.

So I’ve added the --skip-grant-tables option to my docker-compose.yml:


    image: mariadb:10.4
    command: "--skip-grant-tables" # allow to connect with any credentials
    restart: always
      - "3306:3306"
      - type: "bind"
        source: "./db"
        target: "/var/lib/mysql"

I was able to login with any (or none) credentials.