简体   繁体   中英

How to connect to mysql docker container via phpMyAdmin?

I have managed to create two containers, One for PHP-admin and one for mysql while experimenting with docker-compose.

I am able to connect to the mysql container via mysql workbench but when I try to do the same via php I am getting errors.

My docker-compose:

services:
  mysql:
    image: mysql:latest
    ports:
      - 3307:3306
    environment:
      MYSQL_ROOT_PASSWORD: SomeRootPassword1!
      MYSQL_USER: someuser
      MYSQL_PASSWORD: Password1!
      MYSQL_DATABASE: testingDb
    volumes:
      - ./dbScript/create_Script2.sql:/docker-entrypoint-initdb.d/create_Script2.sql
      - db_data:/var/lib/mysql
  phpmyadmin:
    image: phpmyadmin/phpmyadmin
    container_name: dev_pma
    links:
      - mysql
    environment:
      PMA_HOST: mysql
      PMA_PORT: 3308
      PMA_ARBITRARY: 1
    restart: always
    ports:
      - 8183:80
volumes:
  db_data:

When visiting http://localhost:8183/ :

在此处输入图片说明

I also tried localhost:3307 as the server name but same result.

Where have I gone wrong?

EDIT: Im new to docker and assume things were correct since I got no erros but this is the message I get when running docker-compse up:

mysql_1       | 2020-08-26 22:48:58+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.21-1debian10 started.
mysql_1       | 2020-08-26 22:48:58+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
mysql_1       | 2020-08-26 22:48:58+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.21-1debian10 started.
mysql_1       | 2020-08-26T22:48:58.475118Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.21) starting as process 1
mysql_1       | 2020-08-26T22:48:58.485772Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
mysql_1       | 2020-08-26T22:48:58.696157Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
mysql_1       | 2020-08-26T22:48:58.833797Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Bind-address: '::' port: 33060, socket: /var/run/mysqld/mysqlx.sock
mysql_1       | 2020-08-26T22:48:58.905493Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
mysql_1       | 2020-08-26T22:48:58.905743Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel.
mysql_1       | 2020-08-26T22:48:58.910793Z 0 [Warning] [MY-011810] [Server] Insecure configuration for --pid-file: Location '/var/run/mysqld' in the path is accessible to all OS users. Consider choosing a different directory.
mysql_1       | 2020-08-26T22:48:58.936528Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.21'  socket: '/var/run/mysqld/mysqld.sock'  port: 3306  MySQL Community Server - GPL.
dev_pma       | AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 192.168.144.3. Set the 'ServerName' directive globally to suppress this message
dev_pma       | AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 192.168.144.3. Set the 'ServerName' directive globally to suppress this message
dev_pma       | [Wed Aug 26 22:48:59.408472 2020] [mpm_prefork:notice] [pid 1] AH00163: Apache/2.4.38 (Debian) PHP/7.4.8 configured -- resuming normal operations
dev_pma       | [Wed Aug 26 22:48:59.408505 2020] [core:notice] [pid 1] AH00094: Command line: 'apache2 -D FOREGROUND'

Not sure if this means anything but thought I would add it to see if anything might be wrong.

The service name resolves to the IP of DB container.
The port exposed by the container is 3306.

Use mysql (the name of the DB service).
Use 3306 (the port on which the DB container is listening instead of the port on which you are publishing on the host)

在此处输入图片说明

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM