DEV Community

Cover image for Laravel Docker: Install Adminer with a MySQL or PostgreSQL Database
Muhammad Yasir Amin
Muhammad Yasir Amin

Posted on Originally published at yasiramin.dev

Laravel Docker: Install Adminer with a MySQL or PostgreSQL Database

To run Adminer with Laravel in Docker, add an adminer service to your docker-compose.yml, set ADMINER_DEFAULT_SERVER to your database service name, publish a port such as 8081, and open it in the browser. Log in with the same credentials Laravel uses. Adminer is a single-file database manager that works with MySQL, PostgreSQL, SQLite and more, so it suits projects that are not locked to one engine.

This guide uses Laravel 13 (PHP 8.3 or newer) with a MySQL container, then shows how to switch the same Adminer service to PostgreSQL.

Why use Adminer instead of a desktop client?

  • It runs next to your app, so the whole team gets the same tool by running docker compose up.
  • There is nothing to install on the host.
  • It can talk to any database service on the Compose network by name.

What do I need before I start?

  • Docker with the Compose plugin.
  • A Laravel project containerised with a database service. The example calls it db.
  • Matching credentials in the compose file and in Laravel's .env.

Step 1: How do I add the Adminer service?

services:
  db:
    image: mysql:8.4
    environment:
      MYSQL_DATABASE: laravel
      MYSQL_USER: laravel
      MYSQL_PASSWORD: secret
      MYSQL_ROOT_PASSWORD: root-secret
    volumes:
      - db_data:/var/lib/mysql
    networks:
      - app

  adminer:
    image: adminer:latest
    restart: unless-stopped
    depends_on:
      - db
    environment:
      ADMINER_DEFAULT_SERVER: db
    ports:
      - "8081:8080"
    networks:
      - app

volumes:
  db_data:

networks:
  app:
Enter fullscreen mode Exit fullscreen mode

Adminer listens on port 8080 inside the container. The mapping 8081:8080 exposes it as 8081 on your machine so it does not clash with a web server you may already run on 8080. I did not start these containers for this article; check current image tags on Docker Hub and pin one.

Step 2: How do I start and open it?

docker compose up -d adminer
docker compose logs adminer
Enter fullscreen mode Exit fullscreen mode

Open http://localhost:8081. Choose MySQL as the system. The server field is already filled with db. Enter the user laravel, password secret and database laravel.

Step 3: How do I connect Laravel to the same database?

DB_CONNECTION=mysql
DB_HOST=db
DB_PORT=3306
DB_DATABASE=laravel
DB_USERNAME=laravel
DB_PASSWORD=secret
Enter fullscreen mode Exit fullscreen mode
docker compose exec app php artisan migrate --seed
Enter fullscreen mode Exit fullscreen mode

Reload Adminer and open the laravel database. Your tables should be listed. Replace app with your PHP service name.

How do I use Adminer with PostgreSQL?

Replace the database service and the Laravel variables. Adminer does not need a different image:

db:
    image: postgres:17
    environment:
      POSTGRES_DB: laravel
      POSTGRES_USER: laravel
      POSTGRES_PASSWORD: secret
    volumes:
      - pg_data:/var/lib/postgresql/data
    networks:
      - app
Enter fullscreen mode Exit fullscreen mode
DB_CONNECTION=pgsql
DB_HOST=db
DB_PORT=5432
DB_DATABASE=laravel
DB_USERNAME=laravel
DB_PASSWORD=secret
Enter fullscreen mode Exit fullscreen mode

In Adminer choose PostgreSQL as the system. Add pg_data: to the top-level volumes list.

What can I do with Adminer day to day?

  • Inspect the result of a migration or a seeder.
  • Look at rows in the jobs and failed_jobs tables when debugging queues.
  • Run a one-off SQL query and export the result.
  • Compare the table structure with what your migration should have created.

How do I keep Adminer safe?

  • Run it in development only. Do not expose it on a public server.
  • If you need it remotely, bind to localhost, for example "127.0.0.1:8081:8080", and use an SSH tunnel.
  • Use the application database user, not root.
  • Stop the service when you are done: docker compose stop adminer.

What are the common mistakes?

  • Entering localhost as the server. Inside the Adminer container this means Adminer itself. Use the service name, here db.
  • Wrong system selected. Choosing MySQL for a PostgreSQL server gives a connection error.
  • Port conflict. Change the left side of the port mapping.
  • Stale volume. Database credentials only apply when the volume is first created. Changing them later has no effect until you reset the volume, which deletes data.
  • Different networks. The services must share a network for the name to resolve.

How do I verify the setup?

  1. docker compose ps lists adminer and db as running.
  2. The login page opens on port 8081 and accepts your credentials.
  3. After php artisan migrate, the migrations table is visible.

FAQ

What is the difference between Adminer and phpMyAdmin?

Adminer is a single PHP file that supports several database engines. phpMyAdmin focuses on MySQL and MariaDB and has more features for them.

Can Adminer connect to a database outside Docker?

Yes. Enter the host name or IP in the server field. From a container, reaching a database on your host usually needs host.docker.internal on Docker Desktop.

Is it safe to leave Adminer running?

Not on a server reachable from the internet. Treat it like a root-level door to your data.

References


Originally published on yasiramin.dev.

Top comments (0)