New to Docker and I'm trying to set up as a development environment on a Drupal 7 project. I'm running into this error when I visit localhost:8080 after running docker-compose up:
Error
The website encountered an unexpected error. Please try again later.
Error messagePDOException: SQLSTATE[HY000] [2002] No such file or directory in lock_may_be_available() (line 167 of /var/www/html/includes/lock.inc).
It looks like it's having an issue connecting to my database. When I run docker ps -a I can see my 2 containers are up and running, so they seem to build just fine. My issue is just connecting my drupal container to the mysql container.
Here is my docker-compose.yml file:
version: '2'
services:
drupal:
image: drupal:7.53-apache
container_name: app
volumes:
- ./:/var/www/html
ports:
- '8080:80'
links:
- mysql
mysql:
image: mysql:5.6.35
container_name: app_db
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_USER: root
MYSQL_PASSWORD: root
MYSQL_DATABASE: testdb
Am I overlooking something else that would connect the two containers? Any and all help is greatly appreciated. Thanks!
try to map the correct ports and the php DATABASE_HOST. for me this works:
db:
image: dev/mysql
ports:
- "3306:3306"
environment:
MYSQL_DATABASE: testdb
MYSQL_USER: root
MYSQL_PASSWORD: root
php:
image: dev/alpine-nginx-php5.6
environment:
DATABASE_HOST: db
ports:
- "80:80"
- "443:443"
volumes:
- ./SRC:/var/www/
links:
- db
but i would suggest to store your database outside of the docker-container. if you have to rebuild or it has a fatal crash everything is deleted.
Related
I am trying to build a Prestashop image using Docker Compose, I use this docker-compose.yml file
version: "3.7"
services:
app:
build: .
image: prestashop/prestashop:1.7
ports:
- 8080:80
working_dir: /var/www/html
volumes:
- ./:/var/www/html
environment:
PS_DOMAIN: localhost
DB_SERVER: mysql
MYSQL_USER: root
MYSQL_PASSWORD: mypass123
MYSQL_DB: prestashop
dns: 8.8.8.8
mysql:
image: mysql:5.7
environment:
MYSQL_ROOT_PASSWORD: mypass123
MYSQL_DATABASE: prestashop
phpmyadmin:
image: phpmyadmin/phpmyadmin
ports:
- 8081:80
environment:
MYSQL_ROOT_PASSWORD: mypass123
MYSQL_DATABASE: prestashop
PMA_HOST: mysql
But every time I start it, the server does not respond for several minutes (Firefox says "connection was reset"). And once I can eventually access to the webpage, it is very slow.
Is it something that I can solve by changing my docker-compose file ?
Thanks a lot !
You may use .dockerignore in your build.
This helps to avoid unnecessarily sending large or sensitive files and directories to the daemon .
https://docs.docker.com/engine/reference/builder/#dockerignore-file
also check this out for best practices https://docs.docker.com/develop/develop-images/dockerfile_best-practices/
I am a totally beginner at Shopware and I want to use PhpMyAdmin for my local Shopware 6 setup.
For the download I used the official Shopware 6 Development repository https://github.com/shopware/development
I've already seen that the docker-compose.yml has implemented the following:
app_mysql:
build: dev-ops/docker/containers/mysql
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_USER: app
MYSQL_PASSWORD: app
networks:
shopware:
aliases:
- mysql
and now I want to implement phpmyadmin. I tried the following:
phpmyadmin:
image: phpmyadmin/phpmyadmin
links:
- app_mysql:mysql
depends_on:
- app_mysql
ports:
- 8181:80
environment:
PMA_HOST: app_mysql
MYSQL_ROOT_PASSWORD: root
MYSQL_USER: app
MYSQL_PASSWORD: app
phpmyadmin is visible on localhost:8181 but when I try to login I get the following errors:
mysqli::real_connect(): php_network_getaddresses: getaddrinfo failed: Name or service not known
mysqli::real_connect(): (HY000/2002): php_network_getaddresses: getaddrinfo failed: Name or service not known
How can I solve it?
Usually phpmyadmin should be in the same network as the database.
Service names are resolved to the IP addresses of the containers, therefore it's recommended to use names allowed by RFC1035 to avoid additional problems.
I removed links:, aliases, depends_on that are deprecated/not required and ended up with this docker-compose.yml.
version: '3.7'
services:
app-mysql:
#build: dev-ops/docker/containers/mysql
image: mysql
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_USER: app
MYSQL_PASSWORD: app
networks:
- shopware
phpmyadmin:
image: phpmyadmin/phpmyadmin
ports:
- 8181:80
environment:
PMA_HOST: app-mysql
PMA_PORT: 3306
PMA_ARBITRARY: 1
networks:
- shopware
networks:
shopware
Run the containers:
docker-compose up
Open http://localhost:8181/index.php in a browser.
Use
Server: app-mysql
Username: root
Password: root
Enjoy:
You must use as host mysql or app_mysql
It is not an answer, but try
http://localhost:8001/
it is not phpMyAdmin but it is another tool Adminer :)
You should link phpmyadmin and mysql using
links:
- app_mysql:mysql
use it as :
links:
- mysql
Add environment:
`PMA_HOST`: mysql
So whats wrong with this docker-compose.yml? It actually looks ok to me.
But when i try to log in to phpmyadmin on http://localhost:8080/index.php
i get errors:
Packets out of order. Expected 0 received 1. Packet size=71
mysqli_real_connect(): MySQL server has gone away
mysqli_real_connect(): Error while reading greeting packet. PID=33
mysqli_real_connect(): (HY000/2006): MySQL server has gone away
version: "3"
services:
db:
image: mariadb:10.4
volumes:
- test_db_data:/var/lib/mysql
ports:
- "3306:3306"
environment:
MYSQL_DATABASE: test
MYSQL_USER: test
MYSQL_PASSWORD: test
MYSQL_ROOT_PASSWORD: root
networks:
- dbtest
pma:
image: phpmyadmin/phpmyadmin
depends_on:
- db
ports:
- 8080:80
environment:
- PMA_HOST=db
networks:
- dbtest
adminer:
image: adminer
restart: unless-stopped
ports:
- 8081:8080
networks:
- dbtest
volumes:
test_db_data:
networks:
dbtest:
Context:
Docker version 19.03.3
docker-compose version 1.23.2
Update:
I added adminer as well and login also fails.
Mysql stderr shows:
[Warning] Aborted connection 9 to db: 'unconnected' user: 'unauthenticated' host: '192.168.32.3' (This connection closed normally without authentication)
I had the same error and fixed it by deleting the database volume and recreating the database. Not the nicest of solutions. The MySQL server was getting stuck on startup.
I had the luck of it being a database on a dev box so running migrations and reseeding with test data was all I had to do.
Each time when I try to access the phpmyadmin from browser I receive this error:
"Cannot log in to the MySQL server"
I tried to change networks, restart docker.
version: '3'
services:
web:
image: nginx:alpine
ports:
- 80:80
volumes:
- ./public_html:/public_html
- ./conf.d:/etc/nginx/conf.d
networks:
- nginxphp
php:
image: php:7.1.11-fpm-alpine
volumes:
- ./public_html:/public_html
expose:
- 9000
networks:
- nginxphp
db:
image: mysql
environment:
MYSQL_ROOT_PASSWORD: root
ports:
- "3306:3306"
phpmyadmin:
image: phpmyadmin/phpmyadmin
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_USER: root
MYSQL_PASSWORD: root
depends_on:
- db
ports:
- "8080:80"
networks:
nginxphp:
Cannot log in to the MySQL server
mysqli_real_connect(): The server requested authentication method unknown to the client [caching_sha2_password]
mysqli_real_connect(): (HY000/2054): The server requested authentication method unknown to the client
Disclaimer: I'm not a Docker user!
Your didn't mention if you're using the browser on the same computer as the sever or remotely. You'll need access to the mysql server (mysqld) through a terminal (command prompt). If this is a new install, it must be on the computer that is running mysql server.
In the Docker mysql page:
"The default configuration for MySQL can be found in /etc/mysql/my.cnf, which may include additional directories such as /etc/mysql/conf.d or /etc/mysql/mysql.conf.d."
Try looking in the /etc/mysql/my.cnf file on the server you're trying access. first. You're looking for:
bind-address = x.x.x.x
This is the address that the mysql server will talk to ("bound to"). Its typically "localhost" or "127.0.0.1".
To eliminate the error message like you see, I had to do two things:
1) change 'bind-address to 0.0.0.0'
this allows the server to connect to any computer. However, THIS IS A SECURITY RISK. Once you get it working, go read about bind addresses on the mysql website and set it appropriately.
2) Create an new account user#ipaddr where user is the new username and IPAddress is the ip4 address of the computer your trying to connect from. i.e.:
CREATE USER 'user'#'192.168.1.68' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON *.* TO 'user'#'192.168.1.68';
Now try accessing mysql through the terminal program using the new username on the computer with the ip you entered above by typing:
mysql -uuser -ppassword -hx.x.x.x
Hopefully, this will help point you in the right direction. There's a ton of information about bind addresses and security on the web.
Because the phpmyadmin container has connected to the default host localhost. But your mysql server is located in other container (it means you cannot connect to mysql server by using localhost). So in the phpmyadmin service, you have to set PMA_HOST=db. See full env variables: https://hub.docker.com/r/phpmyadmin/phpmyadmin/
Full docker-compose.yml:
version: '3'
services:
web:
image: nginx:alpine
ports:
- 80:80
volumes:
- ./public_html:/public_html
- ./conf.d:/etc/nginx/conf.d
networks:
- nginxphp
php:
image: php:7.1.11-fpm-alpine
volumes:
- ./public_html:/public_html
expose:
- 9000
networks:
- nginxphp
db:
image: mysql
environment:
MYSQL_ROOT_PASSWORD: root
ports:
- "3306:3306"
phpmyadmin:
image: phpmyadmin/phpmyadmin
environment:
PMA_HOST: db
MYSQL_ROOT_PASSWORD: root
MYSQL_USER: root
MYSQL_PASSWORD: root
depends_on:
- db
ports:
- "8080:80"
networks:
nginxphp:
If you are using phpmyadmin with latest mysql version you will have some login issues:
Cannot log in to the MySQL server mysqli_real_connect():
The server requested authentication method unknown to the client [caching_sha2_password] mysqli_real_connect(): (HY000/2054):
The server requested authentication method unknown to the client
The solution is to downgrade to mysql 5.7 or another.
I tested with mysql 5.7 and it works for me.
If you want to can test with another versions and let the community know.
Below is the docker-compose file that builds and run Nginx + php 7.1 + mysql 5.7 +phpmyadmin
version: '3'
services:
web:
image: nginx:alpine
ports:
- 80:80
volumes:
- ./public_html:/public_html
- ./conf.d:/etc/nginx/conf.d
networks:
- nginxphp
php:
image: php:7.1.11-fpm-alpine
volumes:
- ./public_html:/public_html
expose:
- 9000
networks:
- nginxphp
db:
image: mysql:5.7
ports:
- "3306:3306"
environment:
MYSQL_ROOT_PASSWORD: root
phpmyadmin:
image: phpmyadmin/phpmyadmin
links:
- db
environment:
PMA_HOST: db
PMA_PORT: 3306
MYSQL_USER: root
MYSQL_PASSWORD: root
MYSQL_ROOT_PASSWORD: root
depends_on:
- db
ports:
- "8080:80"
networks:
nginxphp:
Hope this will save some time to someone!
Setting up a new Laravel install using docker, this is the docker-compose.yml file:
version: '2'
services:
web:
image: nginx
restart: always
links:
- "fpm"
volumes:
- ./build/volumes/nginx/conf.d:/etc/nginx/conf.d:ro
volumes_from:
- fpm
ports:
- 8080:80
mysql:
image: mysql
environment:
MYSQL_ROOT_PASSWORD: "[OMMITTED]"
MYSQL_DATABASE: "[OMMITTED]"
MYSQL_USER: "[OMMITTED]"
MYSQL_PASSWORD: "[OMMITTED]"
fpm:
build:
context: .
volumes:
- .:/var/www
docker-compose up -d works fine and I can see the web sever at http://localhost:8080/ , however when trying to do any type of connection to the database, I get a PDO::__construct(): php_network_getaddresses: getaddrinfo failed: nodename nor servname provided, or not known error message.
My .env file contains the following ( the DB_HOST is the container name ):
DB_CONNECTION=mysql
DB_HOST=container_mysql_1
DB_PORT=3306
DB_DATABASE=[OMMITTED]
DB_USERNAME=[OMMITTED]
DB_PASSWORD=[OMMITTED]
Attempted to use localhost as the DB_HOST however, it comes back with the Access denied for user error and i've checked that the details are correct. I'm assuming the docker containers are not talking to each other?
You missed docker link:
fpm:
build:
context: .
volumes:
- .:/var/www
links:
- mysql:mysql