According to the docker compose yaml,
version: '3'
services:
db:
image: mariadb:latest
container_name: mariadb
restart: always
volumes:
- ./mysql/initdb/:/docker-entrypoint-initdb.d
- ./mysql/data/:/var/lib/mysql
environment:
- MYSQL_ROOT_PASSWORD=root-pwd
- MYSQL_DATABASE=appdb
- MYSQL_USER=appuser
- MYSQL_PASSWORD=user-pwd
php:
image: php:fpm-alpine
container_name: php
restart: always
volumes:
- ./www/:/var/www/html
expose:
- "9000"
nginx:
image: nginx:alpine
container_name: nginx
restart: always
volumes:
- ./nginx/conf/nginx.conf:/etc/nginx/conf/nginx.conf:ro
- ./nginx/conf.d:/etc/nginx/conf.d:ro
- ./www:/var/www/html
ports:
- "80:80"
pma:
image: phpmyadmin/phpmyadmin
container_name: phpmyadmin
restart: always
ports:
- "8080:80"
it produces an error:
#2002 - php_network_getaddresses: getaddrinfo failed: Try again — The server is not responding (or the local server's socket is not correctly configured).
when logging in to phpMyadmin (http://127.0.0.1:8080).
I have tried to fix this problem, but nothing works.
Could you please find a solution?
Any recommendations/comments are welcomed here.
I had a similar problem try this in the links directive - container-name:db as below
links:
- mariadb:db
you should links your phpmyadmin to database services in order to use the db service
pma:
image: phpmyadmin/phpmyadmin
links:
- db
container_name: phpmyadmin
restart: always
ports:
- "8080:80"
environment:
- PMA_HOST: maria_db
here is more about docker compose services links
If you set the following environment variable in docker compose:
pma:
environment:
- PMA_ARBITRARY=1
then you will be given the opportunity to enter the host server manually on the login screen. Enter the name of the database service there. In your case the name of the service is db
Related
My Docker Wordpress Container some how cannot connect to my database container. I tried to pass the credentials through the environment key.
I'm using external volumes that stores the Data from my previous Wordpress build as well as the data from the Database.
docker-compose.yml
version: '3'
services:
db:
image: mysql:5.7
container_name: db
restart: unless-stopped
env_file: .env
environment:
- MYSQL_DATABASE=wordpress_oxygen
volumes:
- wordpress_db-data:/var/lib/mysql
networks:
- conturas-network
wordpress:
depends_on:
- db
image: wordpress:5.6.0-fpm-alpine
container_name: wordpress
restart: unless-stopped
env_file: .env
environment:
- WORDPRESS_DB_HOST=db:3306
- WORDPRESS_DB_USER=$MYSQL_USER
- WORDPRESS_DB_PASSWORD=$MYSQL_PASSWORD
- WORDPRESS_DB_NAME=wordpress_oxygen
volumes:
- wordpress_data:/var/www/html
networks:
- conturas-network
webserver:
depends_on:
- wordpress
image: nginx:1.19.6-alpine
container_name: webserver
restart: unless-stopped
ports:
- "80:80"
volumes:
- wordpress_data:/var/www/html
- ./nginx-conf:/etc/nginx/conf.d
- certbot-etc:/etc/letsencrypt
networks:
- conturas-network
certbot:
depends_on:
- webserver
image: certbot/certbot
container_name: certbot
volumes:
- certbot-etc:/etc/letsencrypt
- wordpress_data:/var/www/html
command: certonly --webroot --webroot-path=/var/www/html --email username#xyz.io --agree-tos --no-eff-email --force-renewal -d xyz.io -d www.xyz.io
volumes:
certbot-etc:
wordpress_data:
external: true
wordpress_db-data:
external: true
networks:
conturas-network:
driver: bridge
Error Logs from the db-container
...
2020-12-27T15:53:26.593191Z 2 [Note] Access denied for user 'wordpress_oxygen'#'172.30.0.3' (using password: YES)
Thanks for helping!
The very last line of the logs give the important hint on the underlying issue:
[Note] Access denied for user 'wordpress_oxygen'#'172.30.0.3' (using password: YES)
It means that the database credentials used to connect to the database are incorrect - i.e. the username/password combination.
But since this is logged by the database it means WordPress is actually able to connect to the database - i.e. your docker networks are setup correctly.
You should verify now that the values of configured credentials (WORDPRESS_DB_USER, WORDPRESS_DB_PASSWORD etc.) are actually correct - which is the same as MYSQL_USER and MYSQL_PASSWORD used at the time of initializing the database - that is, the environment variables MYSQL_USER, MYSQL_PASSWORD etc. are only used when the database volume is empty and needs to be initialized, see Environment Variables in the image description:
Do note that none of the variables below will have any effect if you start the container with a data directory that already contains a database: any pre-existing database will always be left untouched on container startup.
You may also try to re-initialize the database by deleting the volume and starting a fresh instance of the service.
Also note that environment and env_file two different ways of specifying environment variables for the service, but mixing those two is bad practice since it can lead to unexpected behavior.
If you want to import values from your .env file to use for variable substitution you don't need to "import" it with env_file since it is loaded automatically for docker-compose! I.e. your current configuration does not do what you probably think it does.
What I did to fix the issue
I removed the the environment keys from the whole compose file.
Why did I do this?
I realized with the help of #acran answers, that the volume that I passed into the docker-compose file, was already a ready to use copy of my Initial Wordpress build/installation the same goes for the MySQL Database. (This means all credentials was already stored inside of each volume) Because of that I was not able to pass environment-variables to the composition, to be more precise, you can pass environment-variables to a build but they would simple have no effect on the finished container build.
You can only set environment-variables at the initial build.
Result
version: '3.3'
services:
db:
image: mysql:5.7
container_name: db
restart: unless-stopped
volumes:
- wordpress_db-data:/var/lib/mysql
networks:
- my-network
wordpress:
depends_on:
- db
image: wordpress:5.6.0-fpm-alpine
container_name: wordpress
restart: unless-stopped
volumes:
- wordpress_data:/var/www/html
networks:
- my-network
webserver:
depends_on:
- wordpress
image: nginx:1.19.6-alpine
container_name: webserver
restart: unless-stopped
ports:
- "80:80"
- "443:443"
volumes:
- wordpress_data:/var/www/html
- ./nginx-conf:/etc/nginx/conf.d
- certbot-etc:/etc/letsencrypt
networks:
- my-network
certbot:
depends_on:
- webserver
image: certbot/certbot
container_name: certbot
volumes:
- certbot-etc:/etc/letsencrypt
- wordpress_data:/var/www/html
command: certonly --webroot --webroot-path=/var/www/html --email my.name#xyz.io --agree-tos --no-eff-email --expand --noninteractive -d xyz.io -d www.xyz.io -d dev.xyz.io
volumes:
certbot-etc:
wordpress_data:
external: true
wordpress_db-data:
external: true
networks:
my-network:
driver: bridge
I am trying to containerize my Laravel project. I have the following services in my docker-compose.yml
laravel_app
database
nginx
phpmyadmin
All of them are running okay except PHPMyAdmin. It gets built and does serve the phpMyAdmin login page but I get the following errors when I enter the credentials.
Cannot log in to the MySQL server
mysqli::real_connect(): php_network_getaddresses: getaddrinfo failed: No address associated with hostname
mysqli::real_connect(): (HY000/2002): php_network_getaddresses: getaddrinfo failed: No address associated with hostname
Here is my docker-compose.yml snippet that includes my database service and phpmyadmin service
#The Database
database:
container_name: mysql_database
image: mysql:5.7
volumes:
- dbdata:/var/lib/mysql
environment:
- "MYSQL_DATABASE=dev-db"
- "MYSQL_USER=phpmyadmin"
- "MYSQL_PASSWORD=phpmyadmin"
- "MYSQL_ROOT_PASSWORD=123456"
ports:
- 8991:3306
#PHPMyAdmin Service
phpmyadmin:
container_name: phpmyadmin
image: phpmyadmin/phpmyadmin
ports:
- "8992:80"
depends_on:
- database
environment:
- "PMA_HOST:database"
- "MYSQL_USER:phpmyadmin"
- "MYSQL_PASSWORD:phpmyadmin"
- "MYSQL_ROOT_PASSWORD:123456"
- "UPLOAD_LIMIT:3000000000"
# redis
cache:
image: redis:3.0-alpine
volumes:
dbdata:
For that to work, you need to at least create a bridge network and connect phpmyadmin and your db to it.
Something like this should work:
version: "3"
volumes:
dbdata:
networks:
backend:
driver: bridge
services:
database:
container_name: mysql_database
image: mysql:5.7
volumes:
- dbdata:/var/lib/mysql
environment:
- "MYSQL_DATABASE=dev-db"
- "MYSQL_USER=phpmyadmin"
- "MYSQL_PASSWORD=phpmyadmin"
- "MYSQL_ROOT_PASSWORD=123456"
ports:
- 8991:3306
networks:
- backend
phpmyadmin:
container_name: phpmyadmin
image: phpmyadmin/phpmyadmin
ports:
- "8992:80"
depends_on:
- database
environment:
- "PMA_HOST=database"
- "MYSQL_USER=phpmyadmin"
- "MYSQL_PASSWORD=phpmyadmin"
- "MYSQL_ROOT_PASSWORD=123456"
- "UPLOAD_LIMIT=3000000000"
networks:
- backend
Also I do not recommend exposing DB port
EDITED: Fixed docker-compose file
Like Fominykh Maxim mentioned, my error was caused by syntax error while assigning environment value at phpmyadmin service. I had used PMA_HOST:database instead of PMA_HOST=database
I have a docker compose file which is basically trying to build a WAMP/LAMP style environment.
Basically, PHPMyAdmin can't seem to connect to MySQL. Looking through answers here, it appeared that it was an issue with legacy auth using MySQL Image 8 so I added:
command: --default-authentication-plugin=mysql_native_password
but that didn't work, so I dropped down to mysql image5.7 and the issue is still present. For some reason, I can't connect to MySQL and I get the error:
mysqli_real_connect(): php_network_getaddresses: getaddrinfo failed: Try again
and
mysqli_real_connect(): (HY000/2002): php_network_getaddresses: getaddrinfo failed: Try again
Here is a copy of my Docker Compose which I don't think is doing anything weird.
Hoping someone can clarify that for me.
version: "3.1"
services:
site:
build: .
ports :
- "80:80"
volumes:
- ./www:/var/www/html/
links:
- database
networks:
- php-network
#######################################
# PHP MY ADMIN
#######################################
phpmyadmin:
build:
context: .
dockerfile: PHPMYADMIN.Dockerfile
restart: always
links:
- database:mysql
environment:
PMA_HOST: mysql
PMA_PORT: 3306
ports:
- "8080:80"
environment:
- MYSQL_USERNAME=admin
- MYSQL_PASSWORD=root
networks:
- php-network
#######################################
# MySQL server
#######################################
database:
image: mysql:5.7.25
ports:
- "3306:3306"
container_name: db-mysql
restart: always
environment:
- MYSQL_ROOT_PASSWORD=root
- MYSQL_DATABASE=test_db
- MYSQL_USER=admin
- MYSQL_PASSWORD=root
networks:
- php-network
networks:
php-network:
driver: bridge
I also saw mention of a "depends on" flag which I tried too but that also failed to allow me to connect. I have had the same error throughout.
It's about the container name.
database:
image: mysql:5.7.25
ports:
- "3306:3306"
- **container_name: db-mysql**
and in your phpcontainer:
phpmyadmin:
build:
context: .
dockerfile: PHPMYADMIN.Dockerfile
restart: always
links:
- database:mysql
environment:
**PMA_HOST: mysql**
PMA_PORT: 3306
you define host as mysql, which in docker network will be unrecognizable.
try switching PMA_HOST to db-mysql.
Sorry for bad formatting.
Also use docker ps to see docker container names and to figure out which hosts do you need to connect.
I've got this working now with the following:
version: "3.1"
services:
www:
build: .
ports:
- "8081:80"
volumes:
- ./www:/var/www/html/
links:
- db
networks:
- default
#######################################
# MySQL server
#######################################
db:
image: mysql:5.7.25
ports:
- "3306:3306"
environment:
MYSQL_DATABASE: test_db
MYSQL_ROOT_PASSWORD: test
volumes:
- ./dump:/docker-entrypoint-initdb.d
- persistent:/var/lib/mysql
networks:
- default
#######################################
# PHP MY ADMIN
#######################################
phpmyadmin:
image: phpmyadmin/phpmyadmin
links:
- db:db
ports:
- 8080:80
environment:
MYSQL_USER: user
MYSQL_PASSWORD: test
MYSQL_ROOT_PASSWORD: test
volumes:
persistent:
According to your phpmyadmin service configuration, you are trying to reach mysql container by mysql address:
environment:
PMA_HOST: mysql
PMA_PORT: 3306
But container with mysql server is accessible by database or db-mysql addresses.
So, you need to change phpmyadmin service configuration to:
environment:
PMA_HOST: database
PMA_PORT: 3306
I'm trying to add mysql to a docker compose file, but every time it gives me the error some_name exited with code 0. I tried diffent configurations and even took the following config from the docker docs:
# Use root/example as user/password credentials
version: '3.1'
services:
db:
image: mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: example
adminer:
image: adminer
restart: always
ports:
- 8080:8080
In this case adminer works but mysql doesn't.
My config:
mysqldb:
image: mysql
container_name: ${MYSQL_HOST}
env_file:
- ".env"
environment:
- MYSQL_DATABASE=${MYSQL_DATABASE}
- MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}
- MYSQL_USER=${MYSQL_USER}
- MYSQL_PASSWORD=${MYSQL_PASSWORD}
ports:
- "8989:3306"
Both my config and that from the docker docs keep giving me the same error. Although any other services are working fine. Any ideas?
How unfortunate. After hours I deleted my mysql image and after that everything worked fine.
For the first time I'm using Docker on Digital Ocean for a Wordpress installation. The setup is ok, also the theme installation, but when I install the Revolution Slider plugin the server show me: "Error establishing a database connection".
Plugin installed successfully.
Warning: mysqli_query(): MySQL server has gone away in /var/www/html/wp-includes/wp-db.php on line 1877
Warning: mysqli_query(): Error reading result set's header in /var/www/html/wp-includes/wp-db.php on line 1877
IMAGE COMMAND CREATED STATUS
mysql:latest "docker-entrypoint..." About an hour ago Restarting (1) 12 minutes ago
I restarted all the container, Wordpress works but I can't see any Plugin and the Theme page show me only "ERROR: The theme directory themename does not exist", but looking the FTP the directory is there. Any suggestion? Thanks!
docker-compose.yml
version: '2'
services:
digitalpmi:
container_name: digitalpmi_wp
depends_on:
- db
image: wordpress:latest
restart: always
volumes:
- ./wp-content:/var/www/html/wp-content
environment:
- VIRTUAL_HOST=[ip]
- WORDPRESS_DB_NAME=dpdb
- WORDPRESS_TABLE_PREFIX=dp_
- WORDPRESS_DB_HOST=db
- WORDPRESS_DB_PASSWORD=[password]
networks:
- front
- back
db:
container_name: digitalpmi_db
image: mysql:latest
restart: always
volumes:
- db_data:/var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD:[password]
networks:
- back
phpmyadmin:
container_name: phpmyadmin
depends_on:
- db
image: phpmyadmin/phpmyadmin
restart: always
ports:
- 8181:80
environment:
PMA_HOST: db
MYSQL_ROOT_PASSWORD:[password]
networks:
- back
nginx-proxy:
image: jwilder/nginx-proxy
container_name: nginx-proxy
ports:
- "80:80"
- "443:443"
volumes:
- /var/run/docker.sock:/tmp/docker.sock:ro
networks:
- front
networks:
front:
back:
volumes:
db_data: