Issue
I am trying to set up a basic LAMP stack using docker-compose
but am unable to connect to the mariadb
database using phpmyadmin
when the containers are run.
To try and resolve the issue I stripped back my docker-compose.yaml
file to:
version: '3.2'
services:
db:
image: mariadb
container_name: appsDB
restart: always
ports:
- '6603:3306'
environment:
MYSQL_ROOT_PASSWORD: secret
app:
depends_on:
- db
image: phpmyadmin/phpmyadmin
container_name: phpmyadmin
restart: always
ports:
- '8080:80'
environment:
PMA_HOST: db
When I run the containers I can navigate to the phpmyadmin
page but when I enter the root/secret
username/password I get an error:
Cannot log in to the MySQL server
mysqli::real_connect(): (HY000/2002): php_network_getaddresses: getaddrinfo failed: Name or service not known
To make sure it is not an issue with my computer I also ran docker-compose up
with the database image changed to mysql
and keeping every other detail the same. There was no issue then: phpmyadmin worked fine and I could log into normally with the same root/secret
credentials used in the previous image.
Can anyone advise me why mariadb
behaves this why and is there any way I can access it via phpmyadmin in a docker container?
EDIT
Following advice to check the connection between the containers it seems the mariadb
container database is failing to start. The result from the docker logs is:
2020-07-01 9:32:22 0 [Warning] 'default-authentication-plugin' is MySQL 5.6 / 5.7 compatible option. To be implemented in later versions.
2020-07-01 9:32:22 0 [Note] mysqld (mysqld 10.4.8-MariaDB-1:10.4.8+maria~bionic) starting as process 1 ...
2020-07-01 9:32:22 0 [Note] InnoDB: Using Linux native AIO
2020-07-01 9:32:22 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2020-07-01 9:32:22 0 [Note] InnoDB: Uses event mutexes
2020-07-01 9:32:22 0 [Note] InnoDB: Compressed tables use zlib 1.2.11
2020-07-01 9:32:22 0 [Note] InnoDB: Number of pools: 1
2020-07-01 9:32:22 0 [Note] InnoDB: Using SSE2 crc32 instructions
2020-07-01 9:32:22 0 [Note] mysqld: O_TMPFILE is not supported on /tmp (disabling future attempts)
2020-07-01 9:32:22 0 [Note] InnoDB: Initializing buffer pool, total size = 256M, instances = 1, chunk size = 128M
2020-07-01 9:32:22 0 [Note] InnoDB: Completed initialization of buffer pool
2020-07-01 9:32:22 0 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority().
2020-07-01 9:32:22 0 [ERROR] InnoDB: Invalid flags 0x4800 in ./ibdata1
2020-07-01 9:32:22 0 [ERROR] InnoDB: Plugin initialization aborted with error Data structure corruption
2020-07-01 9:32:23 0 [Note] InnoDB: Starting shutdown...
2020-07-01 9:32:23 0 [ERROR] Plugin 'InnoDB' init function returned error.
2020-07-01 9:32:23 0 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
2020-07-01 9:32:23 0 [Note] Plugin 'FEEDBACK' is disabled.
2020-07-01 9:32:23 0 [ERROR] Could not open mysql.plugin table. Some plugins may be not loaded
2020-07-01 9:32:23 0 [ERROR] Unknown/unsupported storage engine: InnoDB
2020-07-01 9:32:23 0 [ERROR] Aborting
Can anyone advise how I can go about resolving this within docker?
FURTHER EDIT
Just to keep up to date I have found I can start the database container from the CLI with no issues - Database starts and ready to connect:
docker run --name mariadbtest -e MYSQL_ROOT_PASSWORD=mypass -d mariadb
Solution
Are you perhaps working with an outdated version of your images/containers? Your docker-compose.yml works fine for me (my Docker version is 19.03.8, not that I think that should matter).
I'd first try forcing it to recreate the whole stack, docker-compose up --force-recreate
. I noted that you refer to this file as docker-compose.yaml
but the correct default extension should be .yml; if you once created it with a .yml file (or by specifying the file name directly to docker-compose), it's conceivable to me that Docker would silently (or at least un-noticeably) fail to rebuild the new file, so double-check the file names as well.
If that doesn't work, I'd suggest getting in to the shell of the phpMyAdmin container and trying some networking commands to see if you can connect directly; for instance install the mariadb-client
package and try mysql -u root -h db -p
.
Answered By - Isaac Bennetch
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.